Groups | Blog | Home
all groups > dotnet ado.net > december 2005 >

dotnet ado.net : datarow duplication and unique key conflicts


claudio.benghi NO[at]SPAM gmail.com
12/28/2005 11:24:03 AM
Hi all,

I need a quick way to create a new datarow based on an existing one
change a few values and update them to the database (the duplication
should be made in the same db table).

I've seen previous posts suggesting to use the ImportRow method for the
datatable...

i've tried it..

i see rows growing in the "in-memory" datatable... but updating to
database won't work...

any suggestion?

the code i'm using is:

Dim sql As String
sql = "select * from mytable"
Dim dt As New DataTable
Dim da As New OleDbDataAdapter
Dim cm As New OleDbCommand(sql, Conn)
da.SelectCommand = cm

Dim custCB As OleDbCommandBuilder = New OleDbCommandBuilder(da)
da.Fill(dt)
dt.ImportRow(dt.Rows(0))
dt.Rows(3)("myid") = 12

da.Update(dt)

"myid" is a numeric primary key
claudio.benghi NO[at]SPAM gmail.com
12/28/2005 11:28:04 AM
Hey... pushed "Post" before cheering...

:-)

thanks for any Suggestion...
Claudio Benghi
AddThis Social Bookmark Button