473,508 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.Tables.Count is 1, not 0? What kind of DataTable in this
place?
Thanks for help.

Jason
Nov 17 '05 #1
7 2196
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.Tables[0].Rows.Count will return 0.

Pete

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

The SQL string is "select * from Customer where 0 > 1", and the DataSet
should be null.
Why MyDataSet.Tables.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.Tables[yourTable].Rows.Count it will be 0
- If you ask the MyDataSet.Tables[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.Tables.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 FillSqlDataAdapter code:

public void FillSqlDataAdapter(string strFillQry,string DSname)
{
gConn=new SqlConnection();
gConn.ConnectionString=gstrConn;
gDA =new SqlDataAdapter(strFillQry,gConn.ConnectionString);
gDS=new DataSet();
gDA.Fill(gDS,DSname);
gDT=new DataTable();
gDT=gDS.Tables[0];
}// FillSqlDataAdapter

where the gVariable stands for GlobalVariable.

"Chris van Bergen" <cv********@bergler.nl>
???????:ca*************************@news.hccnet.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.Tables[yourTable].Rows.Count it will be 0
- If you ask the MyDataSet.Tables[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.Tables.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
FillSqlDataAdapter?
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**************@TK2MSFTNGP09.phx.gbl...
Thanks Chris!
This is my function FillSqlDataAdapter code:

public void FillSqlDataAdapter(string strFillQry,string DSname)
{
gConn=new SqlConnection();
gConn.ConnectionString=gstrConn;
gDA =new SqlDataAdapter(strFillQry,gConn.ConnectionString);
gDS=new DataSet();
gDA.Fill(gDS,DSname);
gDT=new DataTable();
gDT=gDS.Tables[0];
}// FillSqlDataAdapter

where the gVariable stands for GlobalVariable.

"Chris van Bergen" <cv********@bergler.nl>
???????:ca*************************@news.hccnet.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.Tables[yourTable].Rows.Count it will be 0
- If you ask the MyDataSet.Tables[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.Tables.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 FillSqlDataAdapter.

Jason
"Christiaan van Bergen" <cv********@bergler.nl> ¼¶¼g©ó¶l¥ó·s»D:di**********@azure.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
FillSqlDataAdapter?
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**************@TK2MSFTNGP09.phx.gbl...
Thanks Chris!
This is my function FillSqlDataAdapter code:

public void FillSqlDataAdapter(string strFillQry,string DSname)
{
gConn=new SqlConnection();
gConn.ConnectionString=gstrConn;
gDA =new SqlDataAdapter(strFillQry,gConn.ConnectionString);
gDS=new DataSet();
gDA.Fill(gDS,DSname);
gDT=new DataTable();
gDT=gDS.Tables[0];
}// FillSqlDataAdapter

where the gVariable stands for GlobalVariable.

"Chris van Bergen" <cv********@bergler.nl>
???????:ca*************************@news.hccnet.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.Tables[yourTable].Rows.Count it will be 0
- If you ask the MyDataSet.Tables[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.Tables.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
FillSqlDataAdapter. So if you do not need the adapter gDA outside
FillSqlDataAdapter, make it a local object.

Something like this:

public void FillSqlDataAdapter(string strFillQry,string DSname)
{
if (gConn==null)
{
gConn=new SqlConnection();
gConn.ConnectionString = gstrConn;
}
SqlDataAdapter DA =new SqlDataAdapter(strFillQry,gConn);
gDS=new DataSet();
DA.Fill(gDS,DSname);
if (gDS.Tables.Count>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*************@tk2msftngp13.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 FillSqlDataAdapter.

Jason
"Christiaan van Bergen" <cv********@bergler.nl>
¼¶¼g©ó¶l¥ó·s»D:di**********@azure.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
FillSqlDataAdapter?
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**************@TK2MSFTNGP09.phx.gbl...
Thanks Chris!
This is my function FillSqlDataAdapter code:

public void FillSqlDataAdapter(string strFillQry,string DSname)
{
gConn=new SqlConnection();
gConn.ConnectionString=gstrConn;
gDA =new SqlDataAdapter(strFillQry,gConn.ConnectionString);
gDS=new DataSet();
gDA.Fill(gDS,DSname);
gDT=new DataTable();
gDT=gDS.Tables[0];
}// FillSqlDataAdapter

where the gVariable stands for GlobalVariable.

"Chris van Bergen" <cv********@bergler.nl>
???????:ca*************************@news.hccnet.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.Tables[yourTable].Rows.Count it will be 0
- If you ask the MyDataSet.Tables[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.Tables.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...
0
1768
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...
3
2529
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...
2
1806
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...
3
5627
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...
1
1417
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...
15
2227
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
3685
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...
2
2777
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...
0
7224
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,...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7039
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...
0
5626
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,...
1
5050
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3192
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...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1553
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 ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.