Z
zoneal
The following procedure does not Update the record(s).
'------------------------------------------------------------------
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Dim dadapter As OleDbDataAdapter = New OleDbDataAdapter
Dim CmdBuilder As OleDbCommandBuilder = New
OleDbCommandBuilder(dadapter)
Dim strSelect = "SELECT CustomerID, CompanyName FROM Customers"
Dim cmdSelect As OleDbCommand = New OleDbCommand(strSelect,
Conxn)
Dim DS As DataSet = New DataSet
dadapter.SelectCommand = cmdSelect
dadapter.Fill(DS, "Customers")
Dim strUpdate = "UPDATE " & strCustomers & " " & _
"SET CustomerID = 'COMID', " & _
"CompanyName = 'Cactus Comidas'" & _
"WHERE CustomerID = 'CACTU'"
Dim cmdUpdate As OleDbCommand = New OleDbCommand(strUpdate,
Conxn)
dadapter.UpdateCommand = cmdUpdate
Try
Dim NumRows As Long = dadapter.Update(DS, "Customers")
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
'---------------------------------------------------
For academic purpose, I need a solution based on the Update method of
the DataAdapter (Not ExecuteNonQuery of the
Command object). Please suggest a solution.
'------------------------------------------------------------------
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Dim dadapter As OleDbDataAdapter = New OleDbDataAdapter
Dim CmdBuilder As OleDbCommandBuilder = New
OleDbCommandBuilder(dadapter)
Dim strSelect = "SELECT CustomerID, CompanyName FROM Customers"
Dim cmdSelect As OleDbCommand = New OleDbCommand(strSelect,
Conxn)
Dim DS As DataSet = New DataSet
dadapter.SelectCommand = cmdSelect
dadapter.Fill(DS, "Customers")
Dim strUpdate = "UPDATE " & strCustomers & " " & _
"SET CustomerID = 'COMID', " & _
"CompanyName = 'Cactus Comidas'" & _
"WHERE CustomerID = 'CACTU'"
Dim cmdUpdate As OleDbCommand = New OleDbCommand(strUpdate,
Conxn)
dadapter.UpdateCommand = cmdUpdate
Try
Dim NumRows As Long = dadapter.Update(DS, "Customers")
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
'---------------------------------------------------
For academic purpose, I need a solution based on the Update method of
the DataAdapter (Not ExecuteNonQuery of the
Command object). Please suggest a solution.