Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void btnUpdate_Click(object sender, EventArgs e)
    {

        try
        { 
        string cs = ConfigurationManager.ConnectionStrings["SSMS"].ConnectionString;
        SqlConnection con = new SqlConnection(cs);

        SqlDataAdapter da = new SqlDataAdapter((string)ViewState["SELECT_QUERY"],con);
      SqlCommandBuilder builder = new SqlCommandBuilder(da);

        DataSet ds=(DataSet)ViewState["DATASET"];
        if (ds.Tables["Students"].Rows.Count > 0)
        {
            DataRow dr = ds.Tables["Students"].Rows[0];
            dr["Name"] = txtStudentName.Text;
            dr["Gender"] = ddlGender.SelectedItem;
            dr["TotalMarks"] = txtTotalMarks.Text;
            dr["Id"] = txtStudentId.Text;
        }
        
        da.Update(ds, "Students");
        }
        catch(Exception Ex)
        {

        }
    }
}


What I have tried:

i am trying to run this code then i get error invalidoperationexception was caught in this code
Posted
Updated 16-Feb-16 0:14am
v3

1 solution

So use the debugger, and step through the code.
Put a breakpoint on the line:
C#
string cs = ConfigurationManager.ConnectionStrings["SSMS"].ConnectionString;
And step through teh code looking at exactly what is in each variable. If the execution jumps to the catch block, then it's something to do with the last line it tried to execute - so move your breakpoint and run it again. This time, look very closely at exactly what is in where. It should be fairly obvious what is causing the problem, and that should tell you where to start looking for why that is happening. Or at least have much better information to give us when you ask a question about it! :laugh:

We can't do any of that for you: we can't run your code, and don't have access to your data!
 
Share this answer
 

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