Click here to Skip to main content
16,020,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!

When I am executing the below mentioned code I am getting this error:
"Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information."

Please help me resolve this issue.
C#
protected void Button1_Click(object sender, EventArgs e)
{
    string _connStr = ConfigurationManager.ConnectionStrings["practiceConnectionString"].ConnectionString;
    SqlConnection conn = new SqlConnection(_connStr);
    conn.Open();
    SqlCommand cmd = new SqlCommand("select * from PersonalDetail where id=3", conn);
    DataSet objDataset = new DataSet();
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(objDataset);
    SqlCommandBuilder objCommandBuilder = new SqlCommandBuilder(da);
    da.UpdateCommand = objCommandBuilder.GetUpdateCommand();
    objDataset.Tables[0].Rows[0][1] = "sashibhusan";
    da.Update(objDataset);
    conn.Close();
}


Thanks in advance!
Posted
Updated 9-May-12 2:57am
v2

1 solution

There are two things I can think of from the top of my head what could be wrong here:

  1. The database being addressed does not return any meta data regarding the primary key along with the ususal result set.
  2. Your table PersonalDetail does not contain any primary key at all.


Please edit your question and add what kind of database you are using.

Regards,

Manfred
 
Share this answer
 
Comments
Sandeep Mewara 9-May-12 9:16am    
5!
AFAIR, this should be the reason as per me too.
Manfred Rudolf Bihy 9-May-12 9:26am    
Thanks!

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