Click here to Skip to main content
15,922,894 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have create windows Application(c#3.5 and sql server 2005).In this , I have multiple tables in dataset now i want to bind that to a single DataGridView.Can anybody help me?
Posted
Comments
Prosan 19-Jun-12 7:23am    
elobrate ur question excatly what u wnat.

C#
// method to fill the dataset
public void FillMyDataSet(MyDataSet ds)
{
    string sql = "SELECT a.*, b.* FROM MyTable a JOIN MyOtherTable b ON a.key = b.key";
    using (SqlDataAdapter da = new SqlDataAdapter(sql, conn))
    {
        da.Fill(ds, "MyTable");
    }
}


// call it like this
MyDataSet dsMine = new MyDataSet();
this.FillMyDataSet(dsMine);
MyGridView.DataSource = dsMine;


Or you can try this code.... table mapping is awesome one..


SqlDataAdapter adapter = new SqlDataAdapter(
"SELECT * FROM Customers; SELECT * FROM Orders", connection);
adapter.TableMappings.Add("Table", "Customer");
adapter.TableMappings.Add("Table1", "Order");

adapter.Fill(ds);
 
Share this answer
 
v2
I have multiple tables in dataset now i want to bind that to a single DataGridView
You cannot bind multiple tables to a single datagrid. Only one at a time.
 
Share this answer
 
Comments
Maciej Los 20-Jun-12 10:25am    
Short and to the point! +5
VJ Reddy 20-Jun-12 22:28pm    
Succinct and to the point. 5!
Manas Bhardwaj 21-Jun-12 4:56am    
correct +5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900