Hi,
Before calling the update method of data adapter, you need to set the InsertCommand, UpdateCommand, DeleteCommand properties.
SqlCommandBuilder cb;
cb = new SqlCommandBuilder(TblUsersTableAdapter);
TblUsersTableAdapter.DeleteCommand = cb.GetDeleteCommand(true);
TblUsersTableAdapter.UpdateCommand = cb.GetUpdateCommand(true);
TblUsersTableAdapter.InsertCommand = cb.GetInsertCommand(true);
call update()
TblUsersTableAdapter.Update(MyDataBaseDataSet.tblUsers)
Sample program
-------------
Imports System.Data.SqlClient
Public Class Form1
Dim upd As New Boolean
Dim cb As New SqlCommandBuilder
Dim cn As New SqlConnection("server=.\sqlexpress;database=testdb;uid=sa;pwd=sa123")
Dim dt As New DataTable
Dim da As New SqlDataAdapter
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim squery As String
squery = "Select * from dtl"
da.SelectCommand = New SqlCommand(squery, cn)
da.Fill(dt)
MessageBox.Show(dt.Rows.Count.ToString())
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim dr As DataRow = dt.NewRow
dr(0) = 4
dr(1) = "Shasini"
dr(2) = 5
dt.Rows.Add(dr)
MessageBox.Show(dt.Rows.Count.ToString())
Dim cb As New SqlCommandBuilder(da)
da.DeleteCommand = cb.GetDeleteCommand(True)
da.UpdateCommand = cb.GetUpdateCommand(True)
da.InsertCommand = cb.GetInsertCommand(True)
da.Update(dt)
End Sub
End Class
The above sample works fine and it is inserting the record in the db. Please make sure you are having a Primary Key field in the table.
Best Regards
Muthuraja