Monday, March 26, 2012

Read single piece of data from SqlDataSource to a variable?

First I want to say thanks to the folks how have helped me over the past week or two.

I'm missing a crucial piece of insight. How do I read a single piece of data from a SqlDataSource which only hold one row of data into a declared variable?

string zUserName = SqlDataSource.(get the value in the row that is labeled UserName)

It really doesn't matter to me whether it is an SqlDataSource or some other data container that hold the data I've selected. My goal is to be able to read some data from some predefined datasource into a declared variable.

If I am approaching this problem in the wrong way any advice or article links you could give me would be grealy appreciate.

Thanks, Bill

It's not really meant to do that, but you CAN if you want to by binding the datasource to a hidden field, telling the hidden field to databind, and then picking up its value (Optionally resetting the hidden field to nothing again).

Really want you want is the sqlconnection and sqlcommand for that type of work. SqlDataSource is for populating UI controls with databinding.

No comments:

Post a Comment