Updating a Table

  • Thread starter Thread starter Roshawn Dawson
  • Start date Start date
R

Roshawn Dawson

Hi,

I have three datatables, the last of which represents a many-to-many relationship. Here's how it looks:

Table #1
attID (autoincrement)
Attribute
Name
ProdNumber

Table #2
valID (autoincrement)
Text
Number
Department

Table #3
attID
valID


Here's the scenario. I have an empty database that I'm using. I'm retrieving data from a web
service and placing it in my datatables. I can easily place the desired data into the first two
tables, but not the third one. For that matter, I wouldn't know how to save the data for the third
table.

I'm certain that some ADO.NET guru out there can help me as you've helped many others. Anyone have
any ideas?

Thanks,
Roshawn
 
The design here is flawed. Table3 serves no purpose. If however this was a
DataRelation then it would provide a constraint where entries in the many
side may not exist without an entry in the one side.

I think this is what you are looking for. Furthermore, the DataRelation does
not need to be saved as it acts as your referential intrgrity cop inside the
DataSet
 
Are you trying t get the automatically created value for attID and
valID?

If so, David Sceppa has some code that works to return the values for
autogenerated PKs. Search for his name here.
 
Hi,

I have three datatables, the last of which represents a many-to-many relationship. Here's how it looks:

Table #1
attID (autoincrement)
Attribute
Name
ProdNumber

Table #2
valID (autoincrement)
Text
Number
Department

Table #3
attID
valID


Here's the scenario. I have an empty database that I'm using. I'm retrieving data from a web
service and placing it in my datatables. I can easily place the desired data into the first two
tables, but not the third one. For that matter, I wouldn't know how to save the data for the third
table.

I'm certain that some ADO.NET guru out there can help me as you've helped many others. Anyone have
any ideas?

Thanks,
Roshawn

I believe your third table is a many to many link table. Is that correct? If
so you may have to write code to do the inserts. I don't think the wizards are
smart enough to do that.

I'm on the way to work now, but will work up some code for you this evening, if
some one else hasn't already done that.

Basically, to will need to do it like this:

1. Insert to Table1 and get the primary key (Row id?) for the row.
2. Insert to Table2 and get the primary key (Row id?) for the row.
3. Insert the two primary keys (Row ids?) into the third table.


Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
OHM: great advice

Aziz: appreciate the resource

Otis: it appears that you have just what I'm looking for. Table #3 definitely represents a
many-to-many relationship. The difficulty is inserting the correct data into the table itself
(inserting into the other two tables are simple enough).

Sadly, I haven't found any code using ADO.NET to handle this scenario. However, I am attempting to
restructure the tables to see if I can omit the need for a many-to-many relationship. Might not
prove fruitful, but I'll try anyway.

Thanks,
Roshawn
 
You know what, I misread your post. I thought you were trying to add a
constraint. If you are using table3 threre should be no problem. provided
that the two keys are a composite PK then it should not be any issue at all.
 
Back
Top