Updating a table in DataGidView and Binding Navigator
HI,
Im using VB 2010 express and MS SQL SErver 2008 Express.
I have a form that populate a DataGridView from a table called TblClients and a Binding Navigator.
The code works great and show me all the data. But now I want to add a row and delete a row !
But I cant seem to add a row and delete a row using the BindingNavigator.
Can anyone help. I've looked on line but it's just not clear where to locate the code etc...
See code below...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As New SqlClient.SqlConnection("Server = .\SQLEXPRESS;Database=xxxxx;Trusted_Connection=yes;")
Dim cmd As SqlCommand
Dim da As SqlDataAdapter
Dim ds As DataSet
Dim bsrc As BindingSource
Try
cmd = New SqlCommand("SELECT * FROM TblService", conn)
da = New SqlDataAdapter(cmd)
ds = New DataSet()
da.Fill(ds, "TblService")
'create new binding source
bsrc = New BindingSource()
conn.Open()
bsrc.DataSource = ds.Tables("TblService").DefaultView
'bind BindingSource to Bingding Navigator
Me.BindingNavigator1.BindingSource = bsrc
'bind DataGridView to BindingNavigator's BindingSource
Me.DataGridView1.DataSource = Me.BindingNavigator1.BindingSource
conn.Close()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error!")
End Try
ds = Nothing
End Sub