Problem with using UpdateCommand property

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.
 
C

Cor Ligthert [MVP]

Hi,

Add least do you have to set that commandbuilder, if it has a select
statement and a connection. I woulld not know what it otherwise can build as
commands.

I gues that is your problem

And than remove that hand build update, for that your string is not
sufficient. You miss the information from the select to match to the new
data.

You can drag for that a dataadapber (version 2003) to a new component that
you have added and look what code is generated.

However it is that or the commandbuilder.

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top