Writing Update Back to SQL Server

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am somewhat of a newbie to .NET development and my SqlClient dataset throws
the following runtime error when trying to update rows in a SQL Server table:

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

I am using a SQL Server database that someone else has developed. The table
on which my dataset is based uses a varchar column as the primary key. The
table also has an Identity column and, as a test, if I temporarily remove the
primary key from the varchar column, and re-apply the primary key against the
Identity column, the error no longer occurs. The developer of the database
will not allow this to be a permanent change, so I must reset the varchar
column as the primary key. The error occurs within the following snippet of
code:

Try
Dim cb As New SqlCommandBuilder(dataAdapterObj)

dataRowObj.BeginEdit()
dataRowObj("Image_Column") = Me.OCX_control.Image
dataRowObj.EndEdit()

dataAdapterObj.Update(dataSetObj, "History_Table")

cb.Dispose()
cb = Nothing
Catch xSQL As System.Data.SqlClient.SqlException
 
Joannie,

Does your dataadapter's SelectCommand retrieve the table's primary key
column along with the other columns it retrieves?

Kerry Moorman
 
No, I was not including the table's varchar column in my dataadapter.
But I now have added the column and it looks like this will solve the
problem for me.
Thanks!
 
Back
Top