Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Retrieve Data from SQLDataSource Directly? 1

Status
Not open for further replies.

Andel

Programmer
Joined
Feb 15, 2001
Messages
366
Location
US
I have a SQLDataSource which returns only one row. From that row, I'd like to read a column and display that into my page using a label. Here's my current code that doesn't work:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

lblTitle.Text = SQLDataSource1("ArticleTitle")

End Sub

Thanks in advance.

 
Normally you would map a data source control to something like a Details view and then you can bind the label to a column in the data source.
 
Thanks for the response.

 
However, there is a way to get to the DataTable from the SQLDataSource although I'd say the best method would be to not use the SQLDataSource in the first place if you do have to manipulate the data in ths way.

This method of getting a DataTable is fairly straightforward and can be got to via the Select command of the SQLDataSource and converting the results into a DataTable e.g.
Code:
        Dim dv As New System.Data.DataView
        Dim dt As New System.Data.DataTable
        dv = mySQLDataSource.Select(arguments)
        dt = dv.ToTable()
        Label1.Text = dt.Rows(0).Item("Column1")


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ca8msm, thanks for the response.

what goes to the "arguments" ?

I put "select * from Articles" but it doesn't work.

 
That won't work as the SQLDataSource doesn't have a full blown SQL engine. Instead, have a look at DataSourceSelectArguments as to what it will accept.

I think, although I haven't tred it, you may be able to pass in DataSourceSelectArguments.Empty if you want to retrieve all records.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
That works!

Thanks a lot. I'll give u a star :-)


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top