PC Review


Reply
Thread Tools Rate Thread

DataSet.Table Question

 
 
Jason Huang
Guest
Posts: n/a
 
      24th Sep 2005
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


 
Reply With Quote
 
 
 
 
shiv_koirala@yahoo.com
Guest
Posts: n/a
 
      24th Sep 2005
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/

 
Reply With Quote
 
Pete Davis
Guest
Posts: n/a
 
      24th Sep 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Chris van Bergen
Guest
Posts: n/a
 
      5th Oct 2005
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
>



 
Reply With Quote
 
Jason Huang
Guest
Posts: n/a
 
      6th Oct 2005
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" <(E-Mail Removed)>
???????:(E-Mail Removed)...
> 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
>>

>
>



 
Reply With Quote
 
Christiaan van Bergen
Guest
Posts: n/a
 
      6th Oct 2005
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" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)>
> ???????:(E-Mail Removed)...
>> 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
>>>

>>
>>

>
>



 
Reply With Quote
 
Jason Huang
Guest
Posts: n/a
 
      7th Oct 2005
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" <(E-Mail Removed)> 撰寫於郵件新聞:di3al3$47u$(E-Mail Removed)...
> 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" <(E-Mail Removed)> schreef in bericht
> news:(E-Mail Removed)...
>> 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" <(E-Mail Removed)>
>> ???????:(E-Mail Removed)...
>>> 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
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Christiaan van Bergen
Guest
Posts: n/a
 
      7th Oct 2005
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" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)>
> 撰寫於郵件新聞:di3al3$47u$(E-Mail Removed)...
>> 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" <(E-Mail Removed)> schreef in bericht
>> news:(E-Mail Removed)...
>>> 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" <(E-Mail Removed)>
>>> ???????:(E-Mail Removed)...
>>>> 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
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
basic dataset/table question Aussie Rules Microsoft VB .NET 1 7th Sep 2009 01:32 PM
dataset - table question =?Utf-8?B?Q1NoYXJwZ3V5?= Microsoft ASP .NET 3 11th May 2006 10:09 PM
DataSet table NewRow question Mika M Microsoft ADO .NET 0 19th Apr 2004 01:02 PM
copying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft Dot NET Framework 3 31st Oct 2003 01:05 PM
Parse table from one dataset and create new dataset using this table moondaddy Microsoft ADO .NET 2 22nd Oct 2003 11:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:03 AM.