Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
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
 
Old February 24th, 2006, 12:32 PM
Authorized User
 
Join Date: Feb 2006
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to MAKO
Default 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\"
 
Old February 24th, 2006, 01:33 PM
Authorized User
 
Join Date: Feb 2006
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to MAKO
Default

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-)
 
Old February 25th, 2006, 05:17 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old February 25th, 2006, 12:46 PM
Authorized User
 
Join Date: Feb 2006
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to MAKO
Default

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-)
 
Old February 26th, 2006, 07:39 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Can you show us the rest of the code?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old February 28th, 2006, 08:15 PM
Registered User
 
Join Date: Feb 2006
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
 
Old March 1st, 2006, 06:48 AM
Friend of Wrox
 
Join Date: May 2003
Posts: 229
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Conflict in SQL Server 2000 and SQL Server 2005 ayan.mukherjee SQL Language 0 June 30th, 2008 03:34 AM
migrating from sql server 2000 to sql server 2005 abinashpatra SQL Server 2005 2 December 1st, 2006 03:45 PM
SQL Server 2000 and SQL Server 2000 CE dparsons SQL Server 2000 1 July 31st, 2006 12:59 PM
looking for access 2000 to sql server 2000 sql/que method SQL Server 2000 0 July 7th, 2005 12:46 PM
SQL SERVER 2000 AND ACCESS 2000 ckentebe SQL Server 2000 3 June 17th, 2004 08:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.