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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SqlDataSource control ... binding to a datareader 2

Status
Not open for further replies.

VBRookie

Programmer
May 29, 2001
331
US
Hi ...

I'm using the sqldatasource control to retrieve data. I'd like to bind or dump that data into a datareader so that I can iterate through it and populate some labels on my form. I don't see anyway to do this programmatically ... is this possible?

I have the datasourcemode set to datareader but how do I access the datareader?

Here is my code:
Code:
SqlDataSource1.SelectCommand = "usp_ccTransLog"
   SqlDataSource1.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
   SqlDataSource1.SelectParameters.Add("ActionCode", "SEL")
   SqlDataSource1.SelectParameters.Add("SelectCode", "5")
   SqlDataSource1.SelectParameters.Add("TransactionID", Request.QueryString.Item("TransID"))
   SqlDataSource1.DataSourceMode = SqlDataSourceMode.DataReader
   SqlDataSource1.ConnectionString = DB.GetConn("TestConnect")

Many Thanks,
- VB Rookie
 
All examples I have found use a dataadapter or command object. I see no way of doing it with a sqldatasource.

Jim
 
Thanks again Jim! ... thats what I needed to know. I will have to go another route with this in light of that fact.

Many Thanks,
- VB Rookie
 
Erm...that's not really true. You can use the following method which will return a IDataReader object (if the DataSourceMode property is set to a "DataReader" value)
Code:
SqlDataSource1.Select()




____________________________________________________________

Need help finding an answer?

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

 
ca8msm... thanks for pointing that out. I didn't realize that is the way to do it. In looking for examples in VSHelp, I didn't come acrros that property or any examples... Good to learn something new every day...
 
So what would be the syntax for that? I've tried to do it but select requires some sort of arguments parameter. I thought that I could just do this:

Code:
dim dtRdr = new sqldatareader
dtRdr = sqlDdatasource.select ()

This is the code that I have according to the documentation in the link you posted:

Code:
Dim arguments As DataSourceSelectArguments
  Dim dtRdr As SqlDataReader

SqlDataSource2.SelectParameters.Clear()
  SqlDataSource2.SelectCommand = "usp_ccPriorAuth"
  SqlDataSource2.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
  SqlDataSource2.SelectParameters.Add("ActionCode", "SEL")
  SqlDataSource2.SelectParameters.Add("SelectCode", "1")
  SqlDataSource2.SelectParameters.Add("BatchNbr", drpBatch.SelectedItem.Value)
  SqlDataSource2.ConnectionString = DB.GetConn("MPXExt")
dtRdr = SqlDataSource2.Select(arguments)

  If dtRdr.HasRows Then
   dtRdr.Read()
  End If

It's presently not working ... the .select() method returns an ienumerable object. How do I utilize this as a datareader? Please advise.

Many Thanks,
- VB Rookie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top