SQLDataAdapter.Update(Dataset) Not Working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I've got a windows application / VS.NET 2002 / SQL Server 2000
I'm getting information from different tables of a Cobol DB and storing it
in a single table in a Dataset.
I need to copy all that information into a table of a SQL Server Database.
I've created that table with the same structure of the table in the
CobolDataset.

I'm using the Update method to fill the sqlserver database with the
information, is that right? if not, then please give me suggestions on how to
do it. if it's ok, then tell me why isn't working!

I show the datasets in datagrids and it's successfull (i can see the
information), there's no exception generated (put it in a try catch finally
and never goes to the catch)
Here's the code, tell me what's wrong? why is my sqlserver database still
empty?

Dim sqlautocomando As New SqlCommandBuilder(Me.SqlDataAdapter1)
Me.SqlConnection1.Open()
Me.SqlDataAdapter1.Fill(Me.DataSet11, "tcatalogo")
Me.DataSet11.Merge(ds, True)
Me.SqlDataAdapter1.Update(Me.DataSet11, "tcatalogo")
Me.dgsql.DataSource = Me.DataSet11
Me.SqlConnection1.Close()

pd: connection, adapter and sqldataset generated throw darg&drop and visual
interface. (i've done it manually too, but still not working.)

Thanks
 
I would approach this using DTS or BCP. It would be far faster--and it would
work. I expect the problem with the DataSet you're passing to the Update
method is that the RowState is not "added".

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
www.sqlreportingservices.net
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Regarding to Bill's statement, if you still want to go the ado.net way, you
should set
Me.SqlDataAdapter1.AcceptChangesDuringFill = false
before doing Fill. This way all the rows will be marked as Added and will be
inserted on Update.
 
make sure that source table has primary key. otherwise create Primary key in
the datatable of dataset.

Vamsi

Miha Markic said:
Regarding to Bill's statement, if you still want to go the ado.net way, you
should set
Me.SqlDataAdapter1.AcceptChangesDuringFill = false
before doing Fill. This way all the rows will be marked as Added and will be
inserted on Update.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

MC said:
Hi,
I've got a windows application / VS.NET 2002 / SQL Server 2000
I'm getting information from different tables of a Cobol DB and storing it
in a single table in a Dataset.
I need to copy all that information into a table of a SQL Server Database.
I've created that table with the same structure of the table in the
CobolDataset.

I'm using the Update method to fill the sqlserver database with the
information, is that right? if not, then please give me suggestions on how
to
do it. if it's ok, then tell me why isn't working!

I show the datasets in datagrids and it's successfull (i can see the
information), there's no exception generated (put it in a try catch
finally
and never goes to the catch)
Here's the code, tell me what's wrong? why is my sqlserver database still
empty?

Dim sqlautocomando As New SqlCommandBuilder(Me.SqlDataAdapter1)
Me.SqlConnection1.Open()
Me.SqlDataAdapter1.Fill(Me.DataSet11, "tcatalogo")
Me.DataSet11.Merge(ds, True)
Me.SqlDataAdapter1.Update(Me.DataSet11, "tcatalogo")
Me.dgsql.DataSource = Me.DataSet11
Me.SqlConnection1.Close()

pd: connection, adapter and sqldataset generated throw darg&drop and
visual
interface. (i've done it manually too, but still not working.)

Thanks
 
Hi
Thanks for answering, but in my particular case did not apply.
I had to do it the traditional one-by-one way. and it worked like this:

Dim h, i As Int16
With Me.SqlDataAdapter1
.InsertCommand.Connection.Open()
For i = 0 To ds.Tables(0).Rows.Count - 1
For h = 0 To 18
.InsertCommand.Parameters(h).Value =
ds.Tables(0).Rows(i).Item(h)
Next
.InsertCommand.ExecuteNonQuery()
Next
.InsertCommand.Connection.Close()
.Fill(Me.DataSet11)
End With
ds.Tables(0).TableName = "tcatalogo"
Me.dgcatalogoprendas.DataSource = Me.DataSet11
Me.dgsql.DataSource = ds

Thanks!
 
Back
Top