473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to use SqlDataSource in code

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

Jun 20 '06 #1
1 2077
(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


Jun 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Martin Bischoff | last post by:
Hi, is it possible to modify the values of a SqlDataSource's select parameters in the code behind before the select command is executed? Example: I have an SqlDataSource with a...
8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
1
by: staeri | last post by:
Hello! I would like to set the SqlDataSource in the code behind file and not to have it in the aspx file. How can I do that? Regards, Staeri
3
by: Dorte | last post by:
Hi, Could someone help me with a couple of links to SqlDatasource documentation on how to use the Gridview and SqlDatasource components in code behind? Basically I'm missing some documentation...
3
by: simonZ | last post by:
In gridView I have dropdown list : <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField...
4
by: | last post by:
I'm building some user controls. I very much like how you can build custom properties to be bound to a user control, and how instances of that control will show those custom properties in the...
3
by: Daniel R. H. | last post by:
Hi, I'm having problems to get the value of a Querystring into the SelectCommand of a SQLDataSource, here's my code: ---------------------------------------------- <asp:SqlDataSource...
5
by: msch-prv | last post by:
Hi, I am trying to tie a SQLDataSource control to MySQL without success. The connection string works ok with an ObjectDataSource. (Native asp.net 2.0 MySQL dll loaded in /bin) For some reason,...
2
by: djc | last post by:
1) I am wondering if I should be using an sqlDataSource object for my particular scenario. I need to loop through a listbox and perform an INSERT sql operation for each item. Could be a few or...
4
by: mohaaron | last post by:
This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a GridView during the click event of a button. This...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.