Updating DataSet using InsertCommand property of the DataAdapter

Abbasi

Member
Joined
Nov 2, 2005
Messages
17
Location
Pakistan
Programming Experience
3-5
I trieved the following function from VB.NET help, which does not guide how to commence the InsertCommand property of the DataAdapter in order to physically insert a row into the DataSet. Please help!
------------------------------------------------------------------
Public
Function CreateCustomerAdapter(ByVal conn As OleDbConnection) As OleDbDataAdapter
Dim da As OleDbDataAdapter = New OleDbDataAdapter
Dim cmd As OleDbCommand
cmd =
New OleDbCommand("SELECT * FROM Customers " & _
"WHERE Country = @Country AND City = @City", conn)
cmd.Parameters.Add("@Country", OleDbType.VarChar, 15).Value = "France"
cmd.Parameters.Add("@City", OleDbType.VarChar, 15).Value = "Paris"
da.SelectCommand = cmd
'---------------------------------------------------
Dim DS As DataSet = New DataSet
da.Fill(DS, "Customers")
DataGrid1.DataSource = DS.Tables("Customers")
Dim CB As OleDbCommandBuilder = New OleDbCommandBuilder(da)
'---------------------------------------------------
cmd = New OleDbCommand("INSERT INTO Customers (CustomerID, CompanyName) " & _
"VALUES (@CustomerID, @CompanyName)", conn)
cmd.Parameters.Add("@CustomerID", OleDbType.Char, 5, "CustomerID").Value = "Prime"
cmd.Parameters.Add("@CompanyName", OleDbType.VarChar, 40, "CompanyName").Value = "Prime IT Solutions"
da.InsertCommand = cmd
Dim dt As New DataTable("Customers")
Dim NumRows As Long = da.Update(dt)
MessageBox.Show(NumRows & " Row(s) have been Inserted.", "Inserting Rows Successful.")
Return da
End Function
'---------------------------------------------------
Thanks in anticipation and regards.

R. A. Abbasi

 
Back
Top