 |
| C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 24th, 2006, 12:32 PM
|
|
Authorized User
|
|
Join Date: Feb 2006
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Selecting from SQL Server 2000
I´m having a problem filling various tables into a DataSet for a Windows Forms application. I create de DataSet, declare three string variables for the three different SELECT statements and three dataadapters to fill in the three tables i need. However, when i make a reference to de method that returns the dataset with my three tables, i cannot set datasource of a listbox to tables 2 and/or 3. Can somebody help me please? I`m working under C# 2003
:-Q Marvin B-)
__________________
MAKO - \"El super simio\"
|
|

February 24th, 2006, 01:33 PM
|
|
Authorized User
|
|
Join Date: Feb 2006
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi, everyone! I´ll try to explain in detail
my code is as follows:
public DataSet Clients()
{
DataSet ds = new DataSet();
ds.EnforceConstraints = true;
string select = "SELECT STATEMENT";
string select2 = "SELECT STATEMENT";
string select3 = "SELECT STATEMENT";
try
{
using(SqlConnection conn = new SqlConnection(connectionstring))
{
SqlDataAdapter da = new SqlDataAdapter(select, conn);
SqlDataAdapter da2 = new SqlDataAdapter(select2, conn);
SqlDataAdapter da3 = new SqlDataAdapter(select3, conn);
CreateTable1(ds);//this creates the structure of the table and adds it to the DataSet
da.Fill(ds, "Table1");
CreateTable2(ds);
da.Fill(ds, "Table2");
CreateTable3(ds);
da.Fill(ds, "Table3");
}
}
catch(Exception ex)
{
string e = ex.Message;
}
return ds;
}
With this, when i make an instance of this method on the windows form and try to set the data source of three listboxes, I can only fill with the first table but tables 2 and 3. What am I doing wrong?
:-Q Marvin B-)
|
|

February 25th, 2006, 05:17 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
If you look at the code, I think this one should be easy to spot...
You create three DataAdapters called da1, da2 and da3.
However, you then call the Fill method on da1 only. How come you expect the data from da2 and da3 to go into the DataSet?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

February 25th, 2006, 12:46 PM
|
|
Authorized User
|
|
Join Date: Feb 2006
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well, still not the real problem. Although I made a mistake filling only with da1, the dataset still gets 3 tables (with the same info on each one) and the listsboxes should bind to those tables no matter if they are exactly the same, don´t you think? listbox2 gets the DataSource from table2 correctly, but it is listbox3 that gives me an unhandeled exception error "unable to link to the new displaymember". Still can´t figure out why!
:-Q Marvin B-)
|
|

February 26th, 2006, 07:39 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Can you show us the rest of the code?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

February 28th, 2006, 08:15 PM
|
|
Registered User
|
|
Join Date: Feb 2006
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
|
|
If the three tables have the same structure, you will get the same data three times. But if they have different structure, you get exception.
Mark Chen
|
|

March 1st, 2006, 06:48 AM
|
|
Friend of Wrox
|
|
Join Date: May 2003
Posts: 229
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
you can use three DataAdptapter da1,da2,da3 with DataSet
because adapter fill method takes two parameter(DataSet and Table Name)
eg.
da1 object of DataAdpter
da1.Fill(.DataSet object,"Table Name");
Charul
Charul Shukla
|
|
 |