Newbie: OleDbCommandBuilder won't work

N

Namor

Hi there!

Everyone has no problem with OleDbCommandBuilder but I fighting with
it for quite long time... Nothing special, SQL Server 2000, simple
program in VB.NET that causes no error. When I debug I see that
everything is correct, data in dataset is changed but, no changes in
database.

Here is the code.
Thanks for any help!!


Dim ds As DataSet = New DataSet("myDs")
Dim Adapter As OleDbDataAdapter = New OleDbDataAdapter()
Dim CommandBuilder As OleDbCommandBuilder
Dim r As DataRow
Dim c As DataColumn
Dim sql As String

sql = "SELECT FirstName FROM Persons WHERE id_Person=1"

CommandBuilder = New OleDbCommandBuilder(adapter)
adapter.SelectCommand = New OleDbCommand(sql, connection)
adapter.Fill(ds)

r = ds.Tables(0).Rows(0)
c = ds.Tables(0).Columns("psnFirstNameEng")

r.BeginEdit()
r(c) = "NEW TEXT"
r.EndEdit()

adapter.Update(ds)
 
W

William \(Bill\) Vaughn

First, your problem would be solved more easily if you did not use the
CommandBuilder at all. In this case you can execute an UPDATE statement that
does the same thing with
UPDATE Persons SET FirstName = 'NEW TEXT' WHERE id_Person = 1

Ok, assuming this is just a sample and you're learning, I would approach
addressing the data value like this:

ds.tables(0).rows(0).item("psnFirstNameEng").Value = "NEW TEXT"
adapter.Update(ds.Tables(0))

hth

--
____________________________________
Bill Vaughn
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 

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