Click here to Skip to main content
15,882,152 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I >am trying to approve documents in asp.net when admin login then they approve documents 2 or 3 days ago code works fine now when i again open my project and approve documents it shows me error "Input string was in correct format "

here is the button code.


C#
protected void Button1_Click(object sender, EventArgs e)
    {

        string connStr = 
        ConfigurationManager.ConnectionStrings["mydms"].ConnectionString;
        SqlConnection mySQLconnection = new SqlConnection(connStr);


        try{
            mySQLconnection.Open();
        for (int i = 0; i < Repeater2.Items.Count; i++)
        {
            DropDownList DropDownListcontrol =
            ((DropDownList)Repeater2.Items[i].FindControl("DropDownList4"));
            Label DocId = ((Label)Repeater2.Items[i].FindControl("DocId"));
             SqlCommand cmd = new SqlCommand("approveddd", mySQLconnection);
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.Add("@DocID", SqlDbType.Int).Value = 
             Convert.ToInt32((DocId.Text));

                cmd.Parameters.Add("@ApproveID", SqlDbType.Int).Value = 
              Convert.ToInt32(DropDownListcontrol.SelectedValue);
                cmd.Parameters.Add("@ApproveBy", SqlDbType.VarChar, 50).Value =
              (Session["Login2"]);

                cmd.ExecuteNonQuery();

                DMSLIB.Doc myDoc = new DMSLIB.Doc();
                myDoc.MarkDocAs(Convert.ToInt16(DocId.Text), 
             Convert.ToInt32(DropDownListcontrol.SelectedValue));

            }
        }
           catch (Exception ex)
            {
                apfi.Text = "Error";
            }
         finally
        {
            mySQLconnection.Close();
        }
        }



please any one tell me where is the problem occur... ??
Posted

1 solution

"Input string was in correct format" error came from Convert.ToInt32.
It means, that the value you just passed can not be converted to int.
To see where exactly the error occurs, remove the try-catch-finally block and run again.
 
Share this answer
 
Comments
Diya Ayesa 13-Nov-13 9:15am    
so what i write instead of try catch
Kornfeld Eliyahu Peter 13-Nov-13 9:19am    
Nothing. It's not the source of the error. Removing it will help you find out which of the two Convert.ToInt32 causes the error, and in turn it will tell you the source of the error...
Diya Ayesa 13-Nov-13 9:24am    
removing try catch may be bracket error comes in this...//catch (Exception ex)
//{
apfi.Text = ex.Message;
//}
Kornfeld Eliyahu Peter 13-Nov-13 10:05am    
Of course, you have no ex... Comment this line out too...
Kornfeld Eliyahu Peter 14-Nov-13 6:27am    
It's because you didn't commented out finally - it's part of the try complex...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900