Home All Groups Group Topic Archive Search About

Using SQLDataSource without a control?

Author
24 Aug 2006 6:28 PM
Bill
This  is probably easy but I cannot find it...

All I want to do is read the data out of a SQLDataSource programmatically to
test if there are any records.
I don't want to bind it to a control

I expected to be able to use it like the below

Dim ds as dataset
SqlDataSource1. fill ( ds)    ' does not work

So, can this be done or do I need to create a hidden gridview to receive the
data?

Thanks

Bill

Author
24 Aug 2006 10:18 PM
Spam Catcher
"Bill" <a*@ss.com> wrote in
news:4dmHg.8947$bZ6.7643@tornado.tampabay.rr.com:

> All I want to do is read the data out of a SQLDataSource
> programmatically to test if there are any records.

Use a SQLCommand object... and execute a scalar command like "SELECT COUNT
(1) FROM TABLE"

http://msdn2.microsoft.com/en-
us/library/system.data.sqlclient.sqlcommand.executescalar.aspx
Author
25 Aug 2006 3:37 AM
RJ
I agree with using "Select Count(*)" with a cmd.executeScaler.

But, In your example with DataSource1.Fill..... I think you need
SqlDataAdapter.Fill(ds)


Show quoteHide quote
"Bill" wrote:

> This  is probably easy but I cannot find it...
>
> All I want to do is read the data out of a SQLDataSource programmatically to
> test if there are any records.
> I don't want to bind it to a control
>
> I expected to be able to use it like the below
>
> Dim ds as dataset
> SqlDataSource1. fill ( ds)    ' does not work
>
> So, can this be done or do I need to create a hidden gridview to receive the
> data?
>
> Thanks
>
> Bill
>
>
>
Author
25 Aug 2006 12:51 PM
Bill
Thanks for the suggestions but I was looking for a way to use the
SQLDataSource control to reduce coding,  not using the usual SQL objects.

I did find an answer so here it is:

Dim DV As New DataView

Dim xx As New DataSourceSelectArguments

' get records into dataview

DV = SqlDataSource1.Select(xx.Empty)

' if no active messages then hide link

If DV.Count < 1 Then HyperLink1.Visible = False



Note that the above is ALL of the code needed since I am using the GUI
connection component & wizard to create the connection and string as the
control SQLDataSource1

Bill



Show quoteHide quote
"RJ" <R*@discussions.microsoft.com> wrote in message
news:DBAD8366-DF9B-43C5-80BD-05492CBD5BC3@microsoft.com...
>I agree with using "Select Count(*)" with a cmd.executeScaler.
>
> But, In your example with DataSource1.Fill..... I think you need
> SqlDataAdapter.Fill(ds)
>
>
> "Bill" wrote:
>
>> This  is probably easy but I cannot find it...
>>
>> All I want to do is read the data out of a SQLDataSource programmatically
>> to
>> test if there are any records.
>> I don't want to bind it to a control
>>
>> I expected to be able to use it like the below
>>
>> Dim ds as dataset
>> SqlDataSource1. fill ( ds)    ' does not work
>>
>> So, can this be done or do I need to create a hidden gridview to receive
>> the
>> data?
>>
>> Thanks
>>
>> Bill
>>
>>
>>