Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Datarelation

Status
Not open for further replies.
Feb 20, 2001
24
US
Hi,
I'm just starting out with ASP.net and need some help. I am attempting to create a page with a datagrid that contains data from two different tables. This page is part of a message board system. I want to use a field called UserID in one of my tables, to pull the Name of the user who posted the message from another table in another database. I believe this should be able to be done using a DataRelation, but I just can't figure out exactly what do to. I've tried a few things, but none of them seem to work. Any help would be greatly appreciated. Below is the portion of the code I am using:

dim ds1 as dataset = new Dataset()

BoardCommand.fill(ds1, "tblViewMessage")
UsersCommand.fill(ds1, "tblMainUsers")

dim dr as datarelation = new Datarelation ("MessageUserInfo", ds1.tables("tblMainUsers").columns("ID"), ds1.tables("tblViewMessage").columns("UserID"))
DS1.Relations.Add(dr)

MessageTitleDataGrid.DataSource = ds1.Tables("tblViewMessage").DefaultView
MessageDataGrid.DataSource = ds1.Tables("tblViewMessage").DefaultView
UserDataGrid.DataSource = ds1.Tables("tblMainUsers").DefaultView
Databind()
 
Wouldn't you be better off getting the username in your original SQL Statement rather than have two DataTables in your DataSet?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
you have to add the the data relation to the dataset else its of no use

ds1.Relations.Add(dr)

datagrid1.datasource = ds1.defaultviewmanager
assign the

datagrid1.datamember to the main table.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top