-
problem in DataGrid...
halu...im 3 months aspirant in vb.net i have problem about DataGrid..
i encountered error such as this:
Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.
and here my sample code:
Private ds as DataSet
dim da as SqlDataAdapter
dim cmdtext as string
//form load
ds = new DataSet("customertable")
cmdtext="select * from customertable"
Dim da As New SqlDataAdapter()
da.SelectCommand = New SqlCommand(cmdText, cn)
da.Fill(ds)
DataGrid1.DataSource = ds
//
Private Sub water_reservation_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If ds.HasChanges Then
Dim cb As SqlCommandBuilder
Dim cmd As String = cmdText
da = New SqlDataAdapter(cmd, cn)
cb = New SqlCommandBuilder(da)
Debug.WriteLine(cb.GetInsertCommand.CommandText)
Debug.WriteLine(cb.GetUpdateCommand.CommandText)
Debug.WriteLine(cb.GetDeleteCommand.CommandText)
da.Update(ds)
End If
End Sub
tanx...in advance..:)
-
First: The obvious question is, does the customertable have a key column?
Second: Since you have already associated a SelectCommand with your dataadapter in the form_load event, why are you doing it again in the water_reservation_Closing event?
-
halu...cyberhawke..
tanx for answering my question w/ a question...
i already got it right...:)