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
'---------------------------------------------------
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
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
End SubDim 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 ExceptionMessageBox.Show(NumRows & " Row(s) have been Inserted.", "Rows Inserted Successfully.")
MessageBox.Show(ex.ToString, "Error in Inserting a Row.")
End Try
'---------------------------------------------------
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: