I have populated a DataGridView from the two tables.i am working on windows forms
In page load event I have this code:
Dim adapter As SqlDataAdapter
Dim bSource As BindingSource
Dim dt1 As DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As SqlConnection = New SqlConnection("Data Source=SUPPORT2\SUPPORT2;Initial Catalog=Registry;Persist Security Info=True;User ID=sa;password=solutions") 'SET THE CONNECTION STRING
con.Open()
Dim cd As SqlCommandBuilder = New SqlCommandBuilder(adapter)
adapter = New SqlDataAdapter("select c.CompanyName,d.dtName,d.dtPhone,d.dtEmail from CompanyMaster_tbl c join DepartmentMaster_tbl d on c.Cid=d.cId", con)
dt1 = New DataTable
bSource = New BindingSource
adapter.Fill(dt1)
bSource.DataSource = dt1
gv.DataSource = bSource
End Sub
in update button click i given code like this:
Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click
gv.EndEdit()
bSource.EndEdit()
adapter.Update(dt1)
End Sub
Whenever I edit something in the dataGridView and click update button i am getting error in this line adapter.Update(dt1) :Error:
Update requires a valid UpdateCommand when passed DataRow collection with modified rows.