Hi @Mark Knopfler , Welcome to Microsoft Q&A,
The error you're encountering is due to the way DmCommandBuilder
(or any other DbCommandBuilder
) generates SQL commands for updating or deleting records. The error message indicates that the SelectCommand
does not contain a row version column, which is necessary for optimistic concurrency control. Without a row version column, the command builder cannot generate a safe UpdateCommand
or DeleteCommand
because it can't determine whether a row has changed since it was retrieved.
If you can't add a row version column, you'll need to manually create the UpdateCommand
and DeleteCommand
for the DmDataAdapter
. You can use the DmCommandBuilder
to get the base command and then modify it as needed:
DmCommandBuilder builder = new DmCommandBuilder(ap);
// Manually create the UpdateCommand
DmCommand updateCommand = builder.GetUpdateCommand();
updateCommand.CommandText = "UPDATE YourTable SET Column1 = @Column1 WHERE ID = @ID";
// Add parameters as needed
updateCommand.Parameters.Add(new DmParameter("@Column1", SqlDbType.YourType) { Value = value });
updateCommand.Parameters.Add(new DmParameter("@ID", SqlDbType.YourType) { Value = id });
ap.UpdateCommand = updateCommand;
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.