OleDB Data Adaptor Problem
-
Hi, I wrote code as Public Function UploadData(ByVal UDs As DataSet) As Long Dim SkipRecCnt As Long = 0 For i As Integer = 0 To UDs.Tables(0).Rows.Count - 1 Try SQLCmd.CommandText = UDs.Tables(0).Rows(i)(0).ToString() SQLCmd.ExecuteNonQuery() UDs.Tables(0).Rows(i)(1) = "1" UDs.AcceptChanges() Dim builder As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(AccDa) builder.GetUpdateCommand() AccDa.Update(UDs) Catch ex As Exception SkipRecCnt = SkipRecCnt + 1 End Try Next At line builder.GetUpdateCommand() it is giving following error Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information. Please help me out.
-
Hi, I wrote code as Public Function UploadData(ByVal UDs As DataSet) As Long Dim SkipRecCnt As Long = 0 For i As Integer = 0 To UDs.Tables(0).Rows.Count - 1 Try SQLCmd.CommandText = UDs.Tables(0).Rows(i)(0).ToString() SQLCmd.ExecuteNonQuery() UDs.Tables(0).Rows(i)(1) = "1" UDs.AcceptChanges() Dim builder As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(AccDa) builder.GetUpdateCommand() AccDa.Update(UDs) Catch ex As Exception SkipRecCnt = SkipRecCnt + 1 End Try Next At line builder.GetUpdateCommand() it is giving following error Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information. Please help me out.
You gave the CommandText property the value of a cell in a table instead of giving it a legal SQL query, that also, BTW, returns the primary key column of the table your SELECT statement is querying. The SqlCommandBuilder won't work with a query that returns data from multiple tables, nor will it work with a table that has no primary key.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008