Note that there are some explanatory texts on larger screens.

plurals
  1. POc# sql update - InvalidOperationException
    text
    copied!<p>I am working on a project that needs a database.<br> I have found a tutorial which I've seen in Youtube, and it demonstrates how to connect and edit data with SQL Server 2005.<br> But when I tried it, I receive this error <code>InvalidOperationException</code></p> <p>This is the whole edit code </p> <pre><code>con.Open(); DataTable dt = new DataTable(); //load all records from sample table SqlDataAdapter da = new SqlDataAdapter("select * from sampleEdit where ID=" + textBox1.Text + " ", con); da.Fill(dt); //start the editing of the selected record dt.Rows[0].BeginEdit(); dt.Rows[0][1] = textBox2.Text; //stop the editing dt.Rows[0].EndEdit(); //declare the sql commandbuilder that allow saving of records SqlCommandBuilder cb = new SqlCommandBuilder(da); //update the database da.Update(dt); //close the connection con.Close(); //call the method that display the record to the gridview displayRecords(); </code></pre> <p>The error shows at the update part.<br> What should be the problem?</p> <p>this was the full exception error </p> <pre><code>System.InvalidOperationException: Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information. at System.Data.Common.DbDataAdapter.UpdatingRowStatusErrors(RowUpdatingEventArgs rowUpdatedEvent, DataRow dataRow) at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping) at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping) at System.Data.Common.DbDataAdapter.Update(DataTable dataTable) at DatabaseConnect3.Form1.btnEdit_Click(Object sender, EventArgs e) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload