Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm trying to figure out that best way to load two tables from a database where they have certain relationships. I'll explain more:

I have 2 tables, 1 with information and stuff, and the other has data that directly corresponds with data in the first table. More in detail:

 

First table:

ID Name

1 John

2 Even

......................

 

Second table:

ID LastName:

1 Doe

2 Hitchcock

.......................

 

My question is: I want to get the ID for each column in the first table, and match it with an ID in the second table. Then get the LastName and display it with the first name.

 

Also, if there are more than 1 of that same ID then print all last names with that ID number.

 

I know this probably doesn't make sense, but this isn't my real data, it's just a sample example to see what i can do.

 

Thanks for your time and help!

  • Administrators
Posted

Could you not just write a join statement against the database and capture it's results in a DataTable?

 

SELECT Table1.ID, Name,LastName FROM Table1
JOIN Table2 on Table1.ID = Table2.ID

 

or alternatively have 2 DataTables in a DataSet and create a DataRelation to join them. You can then navigate the relation in code to find all matching records.

 

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndive/html/data07122001.asp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

The joining is not really what im looking for. I'm making an event page, and what i want to do is have users add an event and it will store it into a database. Then if another user replies to that event, it adds the replies in another database, but with the same EventID as the Original Event. So the output i'm really looking for would be something like:

 

FName: John

LName: Doe

FName: Even

LName: Hitchcock

 

 

If that makes any more sense. Thank you for your reply, and i did try that, but it wasn't what i was looking for, it was cool though! lol <-- I'm a n00b to .net and database programming!

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...