在switch语句中获取错误 [英] Getting error in switch statement
本文介绍了在switch语句中获取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须检查3个用户登录我把它们放在下拉列表中。下面我把代码
I have to check 3 users login i put them in dropdown list. Below i put code
string sql_count = string.Format("select count(*) from RegisterMaster where UserId='{0}' and Password='{1}'", TxtUserId.Text, TxtPassword.Text);
string sql = string.Format("select count(*) from AgencyMaster where AgencyName='{0}' and Password='{1}'", TxtUserId.Text, TxtPassword.Text);
string sql_qry = string.Format("select count(*) from AdminMaster where AdminName='{0}' and Password='{1}'", TxtUserId.Text, TxtPassword.Text);
if (TxtUserId.Text != "" && TxtPassword.Text != "")
{
switch (DdlLogin.SelectedIndex)
{
case 0:
{
if (obj.Do_Aggreagate(sql_qry) > 0)
{
Response.Redirect("AdminHome.aspx");
}
else
ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "alert(' Invalid UserName and password !')", true);
break;
}
case 1:
{
if (obj.Do_Aggreagate(sql) > 0)
{
Response.Redirect("AgencyHome.aspx");
}
else
ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "alert(' Invalid UserName and password !')", true);
break;
}
case 2:
{
if (obj.Do_Aggreagate(sql_count) > 0)
{
Response.Redirect("Registration.aspx");
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "alert(' Invalid UserName and password !')", true);
break;
}
}
}
我收到错误不能从一个案例标签(案例:2)到另一个案件标签。请帮帮我
I am getting error cannot fall through from one case label(case:2) to another. Please help me
推荐答案
我认为最后一次休息是在错误的级别(在其他地方),请试试:
I think the last break is at wrong level (inside the else), have a try with:
string sql_count = string.Format("select count(*) from RegisterMaster where UserId='{0}' and Password='{1}'", TxtUserId.Text, TxtPassword.Text);
string sql = string.Format("select count(*) from AgencyMaster where AgencyName='{0}' and Password='{1}'", TxtUserId.Text, TxtPassword.Text);
string sql_qry = string.Format("select count(*) from AdminMaster where AdminName='{0}' and Password='{1}'", TxtUserId.Text, TxtPassword.Text);
if (TxtUserId.Text != "" && TxtPassword.Text != "")
{
switch (DdlLogin.SelectedIndex)
{
case 0:
{
if (obj.Do_Aggreagate(sql_qry) > 0)
{
Response.Redirect("AdminHome.aspx");
}
else {
ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "alert(' Invalid UserName and password !')", true);
}
break;
}
case 1:
{
if (obj.Do_Aggreagate(sql) > 0)
{
Response.Redirect("AgencyHome.aspx");
}
else {
ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "alert(' Invalid UserName and password !')", true);
}
break;
}
case 2:
{
if (obj.Do_Aggreagate(sql_count) > 0)
{
Response.Redirect("Registration.aspx");
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "alert(' Invalid UserName and password !')", true);
}
break;
}
}
您需要移动break
语句:
You need to move thebreak
statement:
case 2:
{
if (obj.Do_Aggreagate(sql_count) > 0)
{
Response.Redirect("Registration.aspx");
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "alert(' Invalid UserName and password !')", true);
break;
}
}
成为
Becomes
case 2:
{
if (obj.Do_Aggreagate(sql_count) > 0)
{
Response.Redirect("Registration.aspx");
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "alert(' Invalid UserName and password !')", true);
}
break;
}
这篇关于在switch语句中获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文