|
-
Jul 12th, 2015, 10:35 AM
#1
Thread Starter
Member
Create Read Update Delete from gridview and save in the database
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()
Dim connectionString As String = "Data Source=MyComputer\SQLEXPRESS;Initial Catalog=APP;" & "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:
Code:
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!
Last edited by Serigraphie; Jul 12th, 2015 at 01:29 PM.
Reason: for security purposes
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|