Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Good Afternoon,

I have a DataSet ds. This contains 2 Tables, Table1 and Table2.

 

I display Table1 on a Grid and Table 2 on another Grid. Table1 is the parent of Table2. When I create a new row on the Grid for Table1, I go to the database to insert the new Table1 row into the Table and get the Table1ID.

For this I define a DataTable dtChanges = ds.Tables["Table1"].GetChanges() and call a stored procedure with table dtChanges. The ID is blank in ds.Tables["Table1"]. However, after my insert into the database I have the real ID. What is the easiest way for me to update ds.Tables["Table1"] with the ID?

 

Thanks

Guha

Posted

You need a few things.

 

1. You need to have the identity (Table1ID) for Table1 set to increment. This means each new row will have a new number.

 

2. You need to make sure there is a relationship between both tables and the changes are set to cascade.

 

This means you have to insert/update table1 prior to table2 and delete in the opposite order.

 

You need the relationship there because if the database is assigning an identity itself, it's not going to be whatever your dataset or you come up with. So when you insert the Table1 Rows, you'll get a new identity when the data refreshes (which should be on an insert really, but depends on the SQL) and when that new identity comes in, it'll cascade to the Table2 foreign keys.

 

Also watch out when you're creating new datatables and copying results and possibly merging things. Huge headache. Even though it's a new object, it still keeps references and causes problems if you don't copy/merge properly. It's all rather counter intuitive as are a few things in a dataset.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...