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

15,137

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();
Share:
15,137
CodeXerox
Author by

CodeXerox

Updated on June 04, 2022

Comments

  • CodeXerox
    CodeXerox almost 2 years
    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);

  • CodeXerox
    CodeXerox over 10 years
    @ Luffy Case _Type_Value is numeric. Case_Status_Value is also numeric.