Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / April 2006

Tip: Looking for answers? Try searching our database.

Updating a Table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Roshawn Dawson - 10 Apr 2006 04:41 GMT
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
OHM ( One Handed Man ) - 10 Apr 2006 05:58 GMT
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

Signature

( OHM ) - One Handed Man
AKA Terry Burns - http://TrainingOn.net

> Hi,
>
[quoted text clipped - 28 lines]
> Thanks,
> Roshawn
Aziz - 10 Apr 2006 10:04 GMT
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.
Otis Mukinfus - 10 Apr 2006 13:02 GMT
>Hi,
>
[quoted text clipped - 26 lines]
>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
Roshawn Dawson - 10 Apr 2006 18:17 GMT
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
OHM ( One Handed Man ) - 10 Apr 2006 18:26 GMT
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.

Signature

( OHM ) - One Handed Man
AKA Terry Burns - http://TrainingOn.net

> OHM:  great advice
>
[quoted text clipped - 12 lines]
> Thanks,
> Roshawn

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.