Illusionist Posted November 18, 2003 Posted November 18, 2003 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! Quote
Administrators PlausiblyDamp Posted November 18, 2003 Administrators Posted November 18, 2003 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 Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Illusionist Posted November 18, 2003 Author Posted November 18, 2003 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! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.