insert into unconnected table

G

Guest

Hi,

I have a dataset with tables that are similar to some empty tables in a
datasource (the table names are the same, and there is the same number of
columns with the same name and type - the schemas are almost identical).
What I need to do, is get data from the tables in my dataset, back into the
datasource. My problem is that the tables in my dataset were not created
from the datasource, and have no mapping to them. What I have tried so far,
is to create an adapter with a connection to the data source, add an insert
command to it, and create table and column mappings. I then call the Update
method on the adapter. After this, I am almost overjoyed to get no
Exceptions, but the empty tables in my datasource, unfortunately, remain
empty. I suspect that my Insert statement is not being called ( the RowState
of the rows that I am trying to write to the data source is "Unchanged").
Maybe I am taking a wrong aproach to this altogether. Anyone feel like they
can help?

Thanks in Advance!
Yuri
 
S

Sahil Malik

Yuri,

You've zero-ed in on the problem. It's because the rowstate's aren't
correct.

How do you fix it? Create a new datatable by doing clone, then do importrow
to the new datatable, and pass that to your dataadapter instead.

Albeit this would be a little demanding on memory, (if your datatables are
huge), it won't be that big a deal from a performance point of view though.
Though you or someone else here might be able to come up with an easier way
of changing the datarow state.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
 
G

Guest

Sahil,
Thanks for the reply; however, when I try your approach, the RowState
remains "Unchanged" after the ImportRow commands are executed. Maybe I am
doing something wrong?

Thanks,
Yuri
 
S

Sahil Malik

Just had another idea.

Do a fill from that particular table into a dataset first. Lets call that
dataset as dsfresh.

Then do a dsfresh.merge(dsnotsofresh) // where dsnotsofresh is the dataset
that contains this table in question.

Then call dataadapter.update(dsfresh.Tables["tableinquestion"])

That's hitting the db twice, but it's lesser code.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
 
W

W.G. Ryan eMVP

In addition to Sahil's comments, if you are simply transferring the data
from the server SourceTable A to datasetA then you need to get taht
dataSetA's data back into Source Table B - You can set teh
acceptChangesDuringFill property to false on the DataAdapter. All of the
rowstate will come in as Inserted... then you can just call Update on a
second adapter pointing to the source table.

It sounds like you're doing some other stuff so this won't work - but it's a
decent approach if it fits your needs.
 

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