简体   繁体   中英

Input string was not in a correct format (ASP.NET)

string s1 = DropDownList1.SelectedItem.Text;
        string s2 = DropDownList2.SelectedItem.Text;
        string sql1 = ("Select Case_Type_Value FROM Case_Type where Case_Type_Text IS'" + s1 + "' ");
        string sql2 = ("Select Case_Status_Value FROM Case_Status where Case_Status_Text IS'" + s2 + "' ");
        int v1 = Int32.Parse(sql1);
        int v2 = Int32.Parse(sql2);

Hi I am getting error "Input string was not in a correct format" on line: int v1 = Int32.Parse(sql1);

Of course you are getting an error! See you are not fetching result from database. Instead you are assigning your query to sql1 and trying to convert it into integer. See below in your code you are actually assigning whole select query to the string sql1.You can try this one :

        string sql1 = ("Select Case_Type_Value FROM Case_Type where Case_Type_Text IS'" + s1 + "' ");
        string sql2 = ("Select Case_Status_Value FROM Case_Status where Case_Status_Text IS'" + s2 + "' ");
sqlconnection con = new SqlConnection("Blah Blah")
    Sqlcommand cmd = new sqlcommand(sql1,con);
con.open();
     int v1 = Convert.toint32(cmd.ExecuteScalar());
con.close();
con.Dispose();

Which type you receive when you

string sql1 = ("Select Case_Type_Value FROM Case_Type where Case_Type_Text IS'" + s1 + "' ");
    string sql2 = ("Select Case_Status_Value FROM Case_Status where Case_Status_Text IS'" + s2 + "' ");

?

you can do one thing just take column called Group like you have taken in the Usertype. Take a session variable and capture username in it.Then get the group to which the username belongs. Based on the role redirect the user to his corresponding page.

    Session["unmae"]=txtuname.text;
string username=Session["unmae"].Text;
string group=obj.getgroup(username);
if(group=="Admin")
{
Response.Redirect("1.aspx");
}
else if(group=="User")

{
Response.Redirect("2.aspx");
}
else
{
Response.Redirect("error.aspx");
}

Hope this helps. Happy coding

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM