943,733 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 3975
  • C# RSS
Nov 28th, 2008
0

Two Tables In DataGridView

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Gaurav arora is offline Offline
59 posts
since Mar 2007
Nov 28th, 2008
0

Re: Two Tables In DataGridView

Dare I ask why? Why not use 2 different views next to each other?
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Nov 28th, 2008
0

Re: Two Tables In DataGridView

Actually I want it to be done throuth DataSets. Actually it is an assignment
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Gaurav arora is offline Offline
59 posts
since Mar 2007
Nov 28th, 2008
0

Re: Two Tables In DataGridView

I meant dataviews as in table on the form, I was expecting it to be 2 datasets.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Dec 3rd, 2008
0

Re: Two Tables In DataGridView

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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Gaurav arora is offline Offline
59 posts
since Mar 2007
Dec 3rd, 2008
0

Re: Two Tables In DataGridView

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

Im guessing if you had tables such as

C# Syntax (Toggle Plain Text)
  1. Table 1
  2. --------
  3.  
  4. id value
  5. 1 5
  6. 2 10
and
C# Syntax (Toggle Plain Text)
  1. table 2
  2. --------
  3. uid name
  4. 3 john
  5. 4 sarah

Im guessing you wanted
C# Syntax (Toggle Plain Text)
  1. id value uid name
  2. 1 5 3 john
  3. 2 10 4 sarah

yes?
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Dec 5th, 2008
0

Re: Two Tables In DataGridView

Hi,
try this

ds1.Merge(ds2);
dataGridView1.DataSource = ds1.Tables[0];
dataGridView1.DataBind();
Reputation Points: 12
Solved Threads: 4
Light Poster
reena12 is offline Offline
32 posts
since Oct 2008
Apr 6th, 2011
0
Re: Two Tables In DataGridView
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
SUNFARMS is offline Offline
1 posts
since Apr 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: how to convert the hashset back to array..
Next Thread in C# Forum Timeline: Closing event of windows form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC