Subject: Selecting from SQL Server 2000
Posted By: MAKO Post Date: 2/24/2006 11:32:42 AM
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-)
Reply By: MAKO Reply Date: 2/24/2006 12:33:06 PM
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-)
Reply By: Imar Reply Date: 2/25/2006 4:17:24 AM
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.
Reply By: MAKO Reply Date: 2/25/2006 11:46:18 AM
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-)
Reply By: Imar Reply Date: 2/26/2006 6:39:22 AM
Can you show us the rest of the code?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply By: MarkMHChen Reply Date: 2/28/2006 7:15:00 PM
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
Reply By: charul_shukla Reply Date: 3/1/2006 5:48:26 AM
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

Go to topic 40745

Return to index page 355
Return to index page 354
Return to index page 353
Return to index page 352
Return to index page 351
Return to index page 350
Return to index page 349
Return to index page 348
Return to index page 347
Return to index page 346