Thursday, March 8, 2012

Convert SqlDataSource to String.

I'm working with an SqlDataSource, and I'm just wondering how to get the data to a String if I'm sure the select statement will only return 1 piece of data. Any ideas?

useExecuteScalar() method of your sql command. it will return the first column of the first row in the result set return by your select query.

|||

Hi,

You can try to use sqldatasource.select with DataView. Try the codes below, i think it should be able to solve your problems

SqlDataSource1.SelectCommand="Your Select Command Here";DataView dv = SqlDataSource1.Select(DataSourceSelectArguments.Empty);string mystr = dv.Table.Rows[0][your colum number].ToString();

Now the string "mystr" should be what you are looking after

Hope my suggestion helps

No comments:

Post a Comment