473,666 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataSet.Table Question

Hi,

The SQL string is "select * from Customer where 0 > 1", and the DataSet
should be null.
Why MyDataSet.Table s.Count is 1, not 0? What kind of DataTable in this
place?
Thanks for help.

Jason
Nov 17 '05 #1
7 2201
You will have a empty table but the row count will be "0".Try for
number of rows in the dataset it should be zero.

-------
Regards ,
C#, VB.NET , SQL SERVER , UML , DESIGN Patterns Interview question book
http://www.geocities.com/dotnetinterviews/
My Interview Blog
http://spaces.msn.com/members/dotnetinterviews/

Nov 17 '05 #2
Because you're actually creating an empty DataTable. It will have the
structure of the Customer table but it will have no rows. Therefore.
MyDataSet.Table s[0].Rows.Count will return 0.

Pete

"Jason Huang" <Ja************ @hotmail.com> wrote in message
news:e5******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

The SQL string is "select * from Customer where 0 > 1", and the DataSet
should be null.
Why MyDataSet.Table s.Count is 1, not 0? What kind of DataTable in this
place?
Thanks for help.

Jason

Nov 17 '05 #3
Hello Jason,

If I get your question right.....
The reason why you will get a DataSet with one DataTable is you asked for
a table. The result is therefor a table, only this time without rows.

also:
- If you ask the MyDataSet.Table s[yourTable].Rows.Count it will be 0
- If you ask the MyDataSet.Table s[yourTable].Columns.Count you will see that
it has as many columns as your table Customer in your database.

Hope this answered your question

Cheers
Christiaan
Hi,

The SQL string is "select * from Customer where 0 > 1", and the
DataSet
should be null.
Why MyDataSet.Table s.Count is 1, not 0? What kind of DataTable in
this
place?
Thanks for help.
Jason

Nov 17 '05 #4
Thanks Chris!
This is my function FillSqlDataAdap ter code:

public void FillSqlDataAdap ter(string strFillQry,stri ng DSname)
{
gConn=new SqlConnection() ;
gConn.Connectio nString=gstrCon n;
gDA =new SqlDataAdapter( strFillQry,gCon n.ConnectionStr ing);
gDS=new DataSet();
gDA.Fill(gDS,DS name);
gDT=new DataTable();
gDT=gDS.Tables[0];
}// FillSqlDataAdap ter

where the gVariable stands for GlobalVariable.

"Chris van Bergen" <cv********@ber gler.nl>
???????:ca***** *************** *****@news.hccn et.nl...
Hello Jason,

If I get your question right.....
The reason why you will get a DataSet with one DataTable is you asked for
a table. The result is therefor a table, only this time without rows.

also:
- If you ask the MyDataSet.Table s[yourTable].Rows.Count it will be 0
- If you ask the MyDataSet.Table s[yourTable].Columns.Count you will see
that it has as many columns as your table Customer in your database.

Hope this answered your question

Cheers
Christiaan
Hi,

The SQL string is "select * from Customer where 0 > 1", and the
DataSet
should be null.
Why MyDataSet.Table s.Count is 1, not 0? What kind of DataTable in
this
place?
Thanks for help.
Jason


Nov 17 '05 #5
Hi Jason,

I notice that you use your dataadapter as a 'global'. Isn't that scope a bit
too big? Do you really need the adapter to live beyond the method
FillSqlDataAdap ter?
Also, as soon as your connection ( gConn ) is created, why not reuse it?
First check if the gConn is null, if so then create a new connection.
And again, do really need those big scoped variables? Do you use them in
other methods or properties?

Chris

"Jason Huang" <Ja************ @hotmail.com> schreef in bericht
news:Og******** ******@TK2MSFTN GP09.phx.gbl...
Thanks Chris!
This is my function FillSqlDataAdap ter code:

public void FillSqlDataAdap ter(string strFillQry,stri ng DSname)
{
gConn=new SqlConnection() ;
gConn.Connectio nString=gstrCon n;
gDA =new SqlDataAdapter( strFillQry,gCon n.ConnectionStr ing);
gDS=new DataSet();
gDA.Fill(gDS,DS name);
gDT=new DataTable();
gDT=gDS.Tables[0];
}// FillSqlDataAdap ter

where the gVariable stands for GlobalVariable.

"Chris van Bergen" <cv********@ber gler.nl>
???????:ca***** *************** *****@news.hccn et.nl...
Hello Jason,

If I get your question right.....
The reason why you will get a DataSet with one DataTable is you asked for
a table. The result is therefor a table, only this time without rows.

also:
- If you ask the MyDataSet.Table s[yourTable].Rows.Count it will be 0
- If you ask the MyDataSet.Table s[yourTable].Columns.Count you will see
that it has as many columns as your table Customer in your database.

Hope this answered your question

Cheers
Christiaan
Hi,

The SQL string is "select * from Customer where 0 > 1", and the
DataSet
should be null.
Why MyDataSet.Table s.Count is 1, not 0? What kind of DataTable in
this
place?
Thanks for help.
Jason



Nov 17 '05 #6
Thanks Chris!
Honestly speaking, when I made up those codes the other days,
I was in a hurry to test how SQL can work in the .Net.
I think the reusing gConn connection is a good idea!
The reason I have the SqlDataAdapter as global is I think it will be more
convient.
every form can use the FillSqlDataAdap ter.

Jason
"Christiaan van Bergen" <cv********@ber gler.nl> ¼¶¼g©ó¶l¥ó·s»D: di**********@az ure.qinip.net.. .
Hi Jason,

I notice that you use your dataadapter as a 'global'. Isn't that scope a
bit too big? Do you really need the adapter to live beyond the method
FillSqlDataAdap ter?
Also, as soon as your connection ( gConn ) is created, why not reuse it?
First check if the gConn is null, if so then create a new connection.
And again, do really need those big scoped variables? Do you use them in
other methods or properties?

Chris

"Jason Huang" <Ja************ @hotmail.com> schreef in bericht
news:Og******** ******@TK2MSFTN GP09.phx.gbl...
Thanks Chris!
This is my function FillSqlDataAdap ter code:

public void FillSqlDataAdap ter(string strFillQry,stri ng DSname)
{
gConn=new SqlConnection() ;
gConn.Connectio nString=gstrCon n;
gDA =new SqlDataAdapter( strFillQry,gCon n.ConnectionStr ing);
gDS=new DataSet();
gDA.Fill(gDS,DS name);
gDT=new DataTable();
gDT=gDS.Tables[0];
}// FillSqlDataAdap ter

where the gVariable stands for GlobalVariable.

"Chris van Bergen" <cv********@ber gler.nl>
???????:ca***** *************** *****@news.hccn et.nl...
Hello Jason,

If I get your question right.....
The reason why you will get a DataSet with one DataTable is you asked
for a table. The result is therefor a table, only this time without
rows.

also:
- If you ask the MyDataSet.Table s[yourTable].Rows.Count it will be 0
- If you ask the MyDataSet.Table s[yourTable].Columns.Count you will see
that it has as many columns as your table Customer in your database.

Hope this answered your question

Cheers
Christiaan

Hi,

The SQL string is "select * from Customer where 0 > 1", and the
DataSet
should be null.
Why MyDataSet.Table s.Count is 1, not 0? What kind of DataTable in
this
place?
Thanks for help.
Jason



Nov 17 '05 #7
Hi Jason,

Well, making a method public can sure be useful this way. But be very
careful with a too big a scope of the variables/objects used inside that
method. Like I mentioned before, the scope of the adapater is very big. And
given your code, you do not release the instance of the adapter. So, this
adapter object will keep on living even after you leave the method
FillSqlDataAdap ter. So if you do not need the adapter gDA outside
FillSqlDataAdap ter, make it a local object.

Something like this:

public void FillSqlDataAdap ter(string strFillQry,stri ng DSname)
{
if (gConn==null)
{
gConn=new SqlConnection() ;
gConn.Connectio nString = gstrConn;
}
SqlDataAdapter DA =new SqlDataAdapter( strFillQry,gCon n);
gDS=new DataSet();
DA.Fill(gDS,DSn ame);
if (gDS.Tables.Cou nt>0)
gDT=gDS.Tables[0];
else
gDT=null;
}

In the code above, the dataadapter will be set ready for garbage collecting
after the method has been completed.
Now you could even place the code "gDS = null;" in the last if-statement so
you can reset the global dataset to null. And that is what you asked for at
first.

Cheers,
Christiaan

"Jason Huang" <Ja************ @hotmail.com> schreef in bericht
news:uP******** *****@tk2msftng p13.phx.gbl...
Thanks Chris!
Honestly speaking, when I made up those codes the other days,
I was in a hurry to test how SQL can work in the .Net.
I think the reusing gConn connection is a good idea!
The reason I have the SqlDataAdapter as global is I think it will be more
convient.
every form can use the FillSqlDataAdap ter.

Jason
"Christiaan van Bergen" <cv********@ber gler.nl>
¼¶¼g©ó¶l¥ó·s»D: di**********@az ure.qinip.net.. .
Hi Jason,

I notice that you use your dataadapter as a 'global'. Isn't that scope a
bit too big? Do you really need the adapter to live beyond the method
FillSqlDataAdap ter?
Also, as soon as your connection ( gConn ) is created, why not reuse it?
First check if the gConn is null, if so then create a new connection.
And again, do really need those big scoped variables? Do you use them in
other methods or properties?

Chris

"Jason Huang" <Ja************ @hotmail.com> schreef in bericht
news:Og******** ******@TK2MSFTN GP09.phx.gbl...
Thanks Chris!
This is my function FillSqlDataAdap ter code:

public void FillSqlDataAdap ter(string strFillQry,stri ng DSname)
{
gConn=new SqlConnection() ;
gConn.Connectio nString=gstrCon n;
gDA =new SqlDataAdapter( strFillQry,gCon n.ConnectionStr ing);
gDS=new DataSet();
gDA.Fill(gDS,DS name);
gDT=new DataTable();
gDT=gDS.Tables[0];
}// FillSqlDataAdap ter

where the gVariable stands for GlobalVariable.

"Chris van Bergen" <cv********@ber gler.nl>
???????:ca***** *************** *****@news.hccn et.nl...
Hello Jason,

If I get your question right.....
The reason why you will get a DataSet with one DataTable is you asked
for a table. The result is therefor a table, only this time without
rows.

also:
- If you ask the MyDataSet.Table s[yourTable].Rows.Count it will be 0
- If you ask the MyDataSet.Table s[yourTable].Columns.Count you will see
that it has as many columns as your table Customer in your database.

Hope this answered your question

Cheers
Christiaan

> Hi,
>
> The SQL string is "select * from Customer where 0 > 1", and the
> DataSet
> should be null.
> Why MyDataSet.Table s.Count is 1, not 0? What kind of DataTable in
> this
> place?
> Thanks for help.
> Jason
>



Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
378
by: Simon Harvey | last post by:
Hi everyone, I was wondering if it is possible, to use SQL to return more than one table at a time into a dataset. I only know the basics of SQL and so I'm not sure if I'm just asking a stupid question. But, I'm not proud! :-) I'm using Ado.net and I'm wanting to load a DataSet object with several independent tables. (For those who arent ADO.net programmers, a DataSet can hold multiple tables and the relationships and contraints...
0
1782
by: Neo | last post by:
I was wondering what is the "right" way to deal with datasets is. Particularly sharing DataSets between forms. Here is my situation. I have a simple Customer Database, that holds some information about Customers including thier address. Lets call this Table "Customers". The Customers Table references another Table for Address information, for instance I have a table of "Zipcodes", Now I want an app with two forms, one form to browse my...
3
2539
by: Diego TERCERO | last post by:
Hi... I'm working on a tool for editing text resources for a family of software product my company produces. These text resources are found in a SQL Server database, in a table called "Resource" with the following structure : Resource{,en,fr,es} Yes.. these are the only languages supported actually. A couple of rows in that table would look like this :
2
1813
by: Simon Harvey | last post by:
Hi everyone, I was wondering if it is possible, to use SQL to return more than one table at a time into a dataset. I only know the basics of SQL and so I'm not sure if I'm just asking a stupid question. But, I'm not proud! :-) I'm using Ado.net and I'm wanting to load a DataSet object with several independent tables. (For those who arent ADO.net programmers, a DataSet can hold multiple tables and the relationships and contraints...
3
5637
by: Mojtaba Faridzad | last post by:
Hi, I am a newbie! I am wondering how DataSet keeps the data. I am using MySQL as database engine. when I use "Fill" method to set a table in DataSet, does C# retreive all data (base on Select statement) to the local computer's memory? if we retreive 100,000 records, does it take a while to load them? another question that I am not sure about it. can we create a table in DataSet without relation to MySQL database? I'd like to create...
1
1423
by: stormogulen | last post by:
Hi! I'm hoping someone can help me come up with a 'best possible solution' for the following problem: I'm trying to design an addressbook, i.e a storage for adresses. I would like my adresses to have a random number of fields, all of which are strings. Futhermore every address can belong to zero or more categories (ie. friend, family etc.)
15
2242
by: JIM.H. | last post by:
Hello, Can I send a dataset as a parameter into stored procedure and import data to a table in the stored procedure? Thanks, Jim.
2
3695
by: Carl Summers | last post by:
I have a table in an Access database that has no sort applied in Access. When I fill a dataset with data from that table (the entire one dimensional table) my dataset is sorted differently than the database. This would not be a problem, and really isn't a problem except that it means I have to search the dataset each time I want to find a particular record instead of just storing a variable. Which brings me to a different question....
2
2783
by: JT | last post by:
I have an SQL database with one table in it. I want to load the table into a DataSet, add new records to the DataSet, then commit the changes back to the database. Using C#.NET, the following loads the DataSet and fills it: string SelectString = "SELECT * FROM dbo.Trade"; SqlCommand RecordsSelection = new SqlCommand(SelectString, ThisConnection);
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8780
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7378
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.