Monday, March 26, 2012

Problems getting information out of a SQLDataSource

I'm working in Visual Studio, I've added a SQLDataSource to the webpage which links to a SQL server database via a DSN (created with the wizard) and it brings back data from a stored procedure with no problems.

I want to access the information from this SQLDataSource in my code and can't seem to get anything from it.

help would be most appreciated.

What do you want to do with the data? Put it in a Gridview? Datalist? Here is a article with a GridView accessing a datasource.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/GridViewEx02.asp

|||I actually want to put the information into a text field rather than a datagrid.|||gave up on that and did it the easy way, all code rather than using the wizards.|||

How would you want to access the information from the SqlDataSource? If you just want to access the database retrieved from database by the Select command, you can do something like this:

SqlDataSource sds = new SqlDataSource(conn.ConnectionString, cmd.CommandText);

DataSourceSelectArguments dssa = new DataSourceSelectArguments();

dssa.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);

DataView dv = (DataView)sds.Select(dssa);

No comments:

Post a Comment