0

Hi all i want to display two unrelated tables in the same datagridview. I m using merge method of datasets but in vain. Any idea Plz

4
Contributors
7
Replies
11
Views
8 Years
Discussion Span
Last Post by SUNFARMS
0

Actually I want it to be done throuth DataSets. Actually it is an assignment

0

Yes LIZr I have 2 DataSets And i Have Merged Them through Merge method of datasets. But Still I m not getting my result
I have Tried following
ds1.Merge(ds2);
dataGridView1.DataSource = ds1.Tables[0].DefaultView;

Any idea plz

0

K, but merge probably doesnt do what you're expecting.

Im guessing if you had tables such as

Table 1
--------

id    value
1     5
2     10

and

table 2 
--------
uid name
3    john
4    sarah

Im guessing you wanted

id value uid name
1  5       3   john
2  10     4   sarah

yes?

0

Hi,
try this

ds1.Merge(ds2);
dataGridView1.DataSource = ds1.Tables[0];
dataGridView1.DataBind();

0

SqlConnection cn = new SqlConnection();

string connstr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Resources\DBMYC.mdf;Integrated Security=True;User Instance=True";
SqlConnection con = new SqlConnection(connstr); //SqlCommand cmd = sqlConnection1.CreateCommand();

SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text; //this has the option of caling a stored procedure
cmd.CommandText = "THE SQL QUERY FOR THE SELECTION FROM TWO TABLES OR MORE";

SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;

//DataSet ds = new DataSet();
//da.Fill(ds, "MYCTAB");

DataTable DT = new DataTable(); //USES DATATABLE INSTEAD OF DATASET
DT.Locale = System.Globalization.CultureInfo.InvariantCulture;
da.Fill(DT);

dataGridView2.DataSource = DT;

THIS WOULD BE OF HELP, IT WORKS.

SUNNY.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.