0

While updating data, I get the following exception:

Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.

Can anyone help me please?

string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
    cn = new SqlConnection(cs);
    da = new SqlDataAdapter("select*from Clinic_info", cn);
    SqlCommandBuilder cmd = new SqlCommandBuilder(da);
    ds = new DataSet();
    da.Fill(ds, "Clinic_info");
    //ds.Tables["Clinic_info"].Constraints.Add("CL_ID_pk", ds.Tables["Clinic_info"].Columns["CL_ID"], true);

    try
    {
        DataRow row;

        row = ds.Tables["Clinic_info"].Rows.Find(Session["msg"].ToString());
        row.BeginEdit();
        row["CL_Name"] = cl_name.Text;
        row["CL_Desc"] = cl_descri.Text;

2 Answers 2

1

Make sure sql table has primary key.

Sign up to request clarification or add additional context in comments.

Comments

1

Make sure you've got select * from Clinic_info in the code instead of select*from Clinic_info. And, as Coder has told you, check the table has a primary key. This is the reason behind the exception.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.