How to use SqlDataSource in code

D

Donald Adams

Can I use the SqlDataSource in code? First I used it to return some rows
and that worked. Then I added the arguements so that I could do paging, but
it threw and exception that I didn't set the SqlDataSourceMode. I did set
it to dataset, but I still get the same exception.
I am calling a stored procedure that returns search results. I don't want
to bind to Gridview or anything like that, I just want the dataset filled
with a specified page.

Is there anything special that I need to know how to do.

Thanks in advance,
Donald
 
D

Donald Adams

(reposted with code sample)
Can I use the SqlDataSource in code? First I used it to return some rows
and that worked. Then I added the arguements so that I could do paging, but
it threw and exception that I didn't set the SqlDataSourceMode. I did set
it to dataset, but I still get the same exception.
I am calling a stored procedure that returns search results. I don't want
to bind to Gridview or anything like that, I just want the dataset filled
with a specified page.

The error message is:

The SqlDataSource '' does not have paging enabled. Set the DataSource to
DataSet to enable paging.

Here's some code:

....
data = new SqlDataSource(eConnect, "dbo.Search");
data.DataSourceMode = SqlDataSourceMode.DataSet;
data.SelectParameters.Add("Search", TypeCode.String, sSearch);
data.SelectCommandType =
SqlDataSourceCommandType.StoredProcedure;
args = new DataSourceSelectArguments();
args.StartRowIndex = 1;
args.MaximumRows = 2;
IEnumerable result = data.Select(args);
if (result != null)
{
dv = (DataView)result;
dv.Table.TableName = "T";
ds = dv.Table.DataSet;
....
This is just a test, so the actual page parameters are fixed.

Is there anything special that I need to know how to do?

Thanks in advance,
Donald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,086
Latest member
ChelseaAmi

Latest Threads

Top