datatable and sql Adapter

D

daveL

Hello,
c#2 , sqlserver 2005

I am parsing a Text File into 2 Datatables
Parent we'll say invoice
child well say Invoice Items

parent rows 10,000, child rows 30,000
the 2 Tables start out Empty, i get the table structures from the Database
"select top 0 from parenttable")
same for the items Table, then i parse the text file into
the 2 Datatables Disconnected from Server

My question is....when inserting into the database
how am i to get the child rows (items) the id key of the parent to complete
the relation in a Batch Update

or do i need to make dynamic sql with @@identity
and insert 1 row Parent set child ids then insert the child rows

is there a example of how to accomplish this with dataset,datatables and
sqlAdapter

Thanks
 
P

Peter Bromberg [C# MVP]

when you select in the data for the parent and child tables, your parent
table will need a primary key ID column, and the child table will need a
"parentID" column that matches which row in the parent table the child row is
associated with.
Then, when you've got your 2 tables in your DataSet, you create a
DataRelation to enforce the relationship.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short Urls & more: http://ittyurl.net
 
D

daveL

Im Inserting into Datatables From a Text File
SqlServer does Not know this is happening
I dont have a Problem setting up the relationship
disconnected...the problem is how to NOT violate primary key/ identity
keyss, when inserting the new data to the database using sqladapter

Thanks
Dave
 
P

Peter Bromberg [C# MVP]

If your database has the correct referential integrity already set up, you
cannot violate it. You can set the ContinueUpdateOnError property on the
DataAdapter, and examine the row errors collection after the update completes
to see which rows weren't inserted because of integrity / restraint
violations.
-- Peter
To be a success, arm yourself with the tools you need and learn how to use
them.

Site: http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://ittyurl.net
 

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