Hi Everyone,
I've been dealing with this issue for four hours now and almost giving up. I just want to ask how create, delete, update and delete can be done with the use of datagrid and update SQL server.
This is what I have:
Private Sub LoadData()
Try
Dim connectionString As String = "Data Source=PHEMSSCGP-L655\SQLEXPRESS;Initial Catalog=COE;" & "Integrated Security=SSPI;"
conn = New SqlConnection(connectionString)
conn.Open()
Dim adap As New SqlDataAdapter("Select SerialNum , BuildNum, PartBuildID , OrderNum , XPart , YPart ,Rot, Height , PartMass , SupportMass , Special FROM tblBuildPlan where BuildNum =" & cmbBuildNum.SelectedValue(), conn)
Dim ds As New DataSet
adap.Fill(ds, "BAM")
GVBuilPlan.DataSource = ds.Tables(0)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
For update button this is what I have:
Try
Dim cmbl As SqlCommandBuilder = New SqlCommandBuilder(da)
cmbl.GetUpdateCommand()
da.Update(ds, "BAM")
MessageBox.Show("Success")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
I can successfully display the values in the db in the gridview but the problem happens when I try to edit or add data and hit update button.
This is the error:
Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.
According to what I read, I have to have a primiary key which I do, and it is the SerialNum from the tblBuildMaster table.
Any help, would be greatly appreciated.
Thank you everyone!