Problem with using InsertCommand property of the DataAdapter

Abbasi

Member
Joined
Nov 2, 2005
Messages
17
Location
Pakistan
Programming Experience
3-5
The following revised procedure still does not commence the InsertCommand property to physically insert a row into the
DataSet.
'------------------------------------------------------------------
Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
Dim DS As DataSet = New DataSet
Dim dadapter As OleDbDataAdapter = New OleDbDataAdapter
Dim CmdBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(dadapter)
Dim strSelect = "SELECT * FROM Customers"
Dim cmdSelect As OleDbCommand = New OleDbCommand(strSelect, Conxn)
dadapter.SelectCommand = cmdSelect
dadapter.Fill(DS, "Customers")
Dim strInsert = "INSERT INTO Customers(CustomerID, CompanyName) " & _
"VALUES('Pak', 'Prime IT Solutions')"
Dim cmdInsert As OleDbCommand = New OleDbCommand(strInsert, Conxn)
dadapter.InsertCommand = cmdInsert
Try
Dim NumRows As Long = dadapter.Update(DS, "Customers")
MessageBox.Show(NumRows & " Row(s) have been Inserted.", "Rows Inserted Successfully.")
Catch ex As Exception
MessageBox.Show(ex.ToString, "Error in Inserting a Row.")
End Try
End Sub
'---------------------------------------------------
Note: I am looking for a solution using Update method of the DataAdapter object, for an academic purpose, and not the ExecuteNonQuery method of the Command object.
Please suggest a solution. Regards.
R. A. Abbasi
 
Last edited:
Back
Top