Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my code i try to update database when changes done in datagridview,for this i have added
Dim cb As New SqlCommandBuilder(adp)

adp.Update(ds, "tablename")
At adp.update(ds,"tablename")am getting Error:Dynamic sql generation for the update command is not supported against a select command that does not return any key column information
May i know the reason plz..
Posted
Updated 4-Jul-20 18:13pm
Comments
mukehs tyagi 31-Aug-12 3:13am    
main droup down ki value ko datagridview main show krakar us vlue ko update karna hai in C# plz send me code

You Have to Mention primary key in your Table.then before executing update command of dataApdapter you have to set update command of dataAdapter with CommandBuilder object like this 

--- create connection ----
SqlDataAdapter adp = new SqlDataAdapter();
SqlCommandBuilder bldr;

bldr=new SqlCommandBuilder(adp);
adp.UpdateCommand = bldr.GetUpdateCommand();
adp.Update(ds.Tables[0]);
 
Share this answer
 
The table you're running the SELECT against doesn't have a primary key column. It cannot create any other UPDATE or DETELE statements because you have no way of uniquely identifying every single record in your table.
 
Share this answer
 
Comments
Member 7940184 23-May-11 0:56am    
But my table have primary key already and am using identity for autoincrement that value.is it the problem for getting those error.
Dave Kreskowiak 23-May-11 7:25am    
Then your SELECT query isn't returning the primary key column. The column has to be MAKRED as the primary key. You cannot just assign values yourself to this column, treat is like a key column and expect it to work.

Thakur Varun Singh 18-May-13 3:57am    
Ya Dave you are absolutely wright
PotatoJam 25-May-12 3:32am    
thanks
ernestmachado 29-Aug-12 6:46am    
but Why Primery Key Needed Without Primary Key I Cannot Update Or Delete row in Table?????
yes, this problem is resolved by update the primary key in your table because of data update and delete by unique data column.
 
Share this answer
 
Comments
Richard Deeming 23-Nov-15 10:12am    
This question was asked, answered and solved over FOUR AND A HALF YEARS AGO!
I've spent two days to find some way to workaround. Lucky that I could get it done. The idea is to add a dump primary key in the DataTable, this new dump column does not affect the real database table. Here's my code sample

Dim currentRow = m_DataTable.Rows(m_RowPosition) Dim tmpRows() As DataRow = {currentRow}


Dim cmdBuilder As OracleCommandBuilder = New OracleCommandBuilder(m_Adapter)

       **If m_DataTable.PrimaryKey.Count = 0 Then
           m_DataTable.Columns.Add(New DataColumn("_ID_", System.Type.GetType("System.String")))
           m_DataTable.Columns("_ID_").Unique = True
       End If**

       m_Adapter.Update(tmpRows)


Note: The currentRow is the row is being edited . Please consider carefully to apply this tip because it might update all data of table. It's suitable for case your table has only one row ( some kind of configuration data )
 
Share this answer
 

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