Moaataz Aamer
Moaataz Aamer

Reputation: 9

Displaying a datalist

I've a problem wiz binding a datalist from 2 tables .... I used this code DataSet ds = DataManager.ExecuteDataSet("select_unionmembers_full_info");

    ds.Tables[0].TableName = "unionmembers";
    ds.Tables[1].TableName = "user_sign_up";

    ds.Relations.Add(new DataRelation("stunion", ds.Tables["unionmembers"].Columns["stuid"],

    ds.Tables["user_sign_up"].Columns["stu_id"], false));

    alreadyexistdl.DataSource = ds.Tables[0];

    alreadyexistdl.DataBind();
} 

and here is the join query I used (select_unionmembers_full_info)
select * , username,id from unionmembers , user_sign_up where stuid=stu_id and this error appears to me !
Cannot find table 1.
Line 14: Line 15: ds.Tables[0].TableName = "unionmembers"; Line 16: ds.Tables[1].TableName = "user_sign_up"; Line 17: Line 18: ds.Relations.Add(new DataRelation("stunion", ds.Tables["unionmembers"].Columns["stuid"]

here is the Stack Trace:

 [IndexOutOfRangeException: Cannot find table 1.]

System.Data.DataTableCollection.get_Item(Int32 index) +79 stunion_unionadmin.Page_Load(Object sender, EventArgs e) in g:\New graduation project_2\Do7h Book 1\stunion\unionadmin.aspx.cs:16 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51 System.Web.UI.Control.OnLoad(EventArgs e) +92 System.Web.UI.Control.LoadRecursive() +54 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +670

Upvotes: 1

Views: 123

Answers (1)

smoore4
smoore4

Reputation: 4866

In order to get two table results, you need to pass two db commands. Like this for example:

CommandString = "SELECT foo0 FROM foo0; SELECT foo1 FROM foo1;";
sda = new SqlDataAdapter(CommandString, conn);
ds = new DataSet();
sda.Fill(ds);
dt = ds.Tables[0];
dt1 = ds.Tables[1];

Upvotes: 0

Related Questions