i want to display some column of table 2 as well as table1 in a single grid,,,
plz provide me code with example....
thanks..
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Amit ChoudharyPosted Mar 24, 2010, 5:14 AM
if you don't want to join the tables then you can do following:
Create a dataset fill it with data from table1...
Dataset ds=new DataSet();
adp.fill(ds);
now you can add columns to your dataset...
DataColumn dc=new DataColumn("Col_tabl2",System.Type.GetType("SystemString"));
ds.Columns.Add(dc);
now you add rows from table2 manually...
Get the data from Table 2 in datareader and add it to the specific column like this:
DataReader rdr=cmd.ExecuteReader();
for(int i=0;i
ds.Tables[0].Rows[i]["Col_tab2"]=rdr["Col_tab2"].ToString();
}
Similarly you can add more column and rows manually to your dataset and
finally bind your Grid.
Please mark as answer if it helps.
VasanthPosted Mar 24, 2010, 4:39 AM
Page.cs--------
using System.Data;using System.Configuration;using System.Data.SqlClient;
void Page_Load(Object sender, EventArgs e){// Connection open// bind the data sourcedgSample.DataBind();
// Connection closedmyConn.Close();