Dear Friends
I have a problem. I want to fill dataset by executing query on multiple tables and then capture data in comboboxes.
and also combox1.datasource=ds.tables["which table name or what should i write here?"]
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Suresh PaldiaRank #1,206 · 1.5K reputationPosted Nov 11, 2010, 2:35 AM EST
Example:
String query = "SELECT A.firstname FROM
EMPLOYEETABLE AS A
INNER/LEFT/RIGHT/FULL JOIN
ADDRESSTABLE AS B
ON somecondition";
SqlDataAdapter a = new SqlDataAdapter(query,con);
DataSet ds = new DataSet();
a.Fill(ds,"resulttable");
ComboBox1.DataSource = ds;
Manikavelu VelayuthamRank #413 · 6K reputationPosted Nov 11, 2010, 2:21 AM EST
There you can join multiple table and fetch the needed values.
Finally you can fill it in a dataset.
Mayur Gujrathi85 reputationPosted Nov 11, 2010, 6:43 PM EST
Whats This "resulttable". Please give me some brief exposure,Its Urgent. I didnt understood
Thank You
String query = "SELECT A.firstname FROM
EMPLOYEETABLE AS A
INNER/LEFT/RIGHT/FULL JOIN
ADDRESSTABLE AS B
ON somecondition";
SqlDataAdapter a = new SqlDataAdapter(query,con);
DataSet ds = new DataSet();
a.Fill(ds,"resulttable");
ComboBox1.DataSource = ds;
Suresh PaldiaRank #1,206 · 1.5K reputationPosted Nov 11, 2010, 9:12 PM EST
a.Fill(ds,"resulttable");
Now, in future you can refer/map to that table by using
ComboBox1.DataSource = ds.Table["resulttable"]
But in case my query itself is returning more than 1 tables, for example
string stmt = "SELECT name FROM Customer
SELECT ordernumber FROM Order
SELECT recieptnumber FROM RecieveDetails";
Or you might use a stored procedure that returns multiple tables.
Code above will result in 3 DataTables called "Table", "Table1", "Table2" by default if i use -
a.Fill(ds);
ComboBox1.DataSource = ds.Tables["Table"];
ComboBox2.DataSource = ds.Tables["Table1"];
ComboBox3.DataSource = ds.Tables["Table2"];
And it will return 3 datatables called "resulttable", "resulttable1" and "resulttable2" if i use -
a.Fill(ds,"resulttable");
ComboBox1.DataSource = ds.Tables["resulttable"];
ComboBox2.DataSource = ds.Tables["resulttable1"];
ComboBox3.DataSource = ds.Tables["resulttable2"];
Accordingly, you will have to refer these tables by these names only.
But, i recommend you to add a TableMapping for each table returned by your statement.
You can do this as,
SqlDataAdapter da= new SqlDataAdapter(stmt, sqlConnection);
da.TableMappings.Add("Table", "Customer");
da.TableMappings.Add("Table1", "Order");
da.TableMappings.Add("Table2", "RecieveDetails");
da.Fill(dataset);
Then you can use;
ComboBox1.DataSource = ds.Tables["Customer"];
ComboBox2.DataSource = ds.Tables["Order"];
ComboBox3.DataSource = ds.Tables["RecieveDetails"];
More meaningful... isn't it!
Hope you got this concept...
For more about Table Mapping, you can visit
http://msdn.microsoft.com/en-us/library/ms810286.aspx
Happy Learning...
Mayur Gujrathi85 reputationPosted Nov 11, 2010, 9:19 PM EST
Suresh PaldiaRank #1,206 · 1.5K reputationPosted Nov 11, 2010, 10:48 PM EST
Suresh PaldiaRank #1,206 · 1.5K reputationPosted Nov 11, 2010, 10:50 PM EST
Mahesh ChandRank #1 · 393.3K reputationPosted Nov 11, 2010, 2:27 AM EST
comboBox1.DataSource = ds.Tables["Customers];
So what you need to do is, either create a relationship in your database and use the JOIN SQL query OR you can add a relationship in the DataRelation (you probably don't need this).