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

2

13

I want update/edit data in database (MS Access) by using DataGridView in VB.net I used this code:

       Dim sadapter As OleDb.OleDbDataAdapter
       Dim sds As DataSet
       sadapter.Update(sds, "marks") 

then showing this message:

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

Estuarine answered 26/12, 2012 at 20:30 Comment(3)
The error says it all. The code used to fill the DataGridView through the OleDbDataAdapter has not returned any information on the primary key of your table. What is the code used to fill the grid?Achilles
Which row should it update? You haven't given it any key it can use to decide which row to update.Tomtom
The table schema needs to have a primary key defined.Three
C
15

If you table doesn't have a primary key, you need to set one.

Charters answered 31/10, 2013 at 8:19 Comment(2)
Hello, thanks, it worked. What's the reason behind?Merth
System need to know which record/records you want to be updated. To know this it needs primary/unique key. (There may be two exact same record in your table. A unique key column makes these two unique in that table.)Grudge
C
1

If your table doesn't have a primary key you can use SqlDataAdapter.Fill

Clevie answered 18/6, 2021 at 15:20 Comment(1)
I don't think this answers the question which was how to do an update. Fill won't help in for updates. I think you misunderstood the question. Nashath Nasik had the correct answer.Credo

© 2022 - 2024 — McMap. All rights reserved.