473,748 Members | 7,827 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to access parameters of SqlDataSource

Hi,

I am trying to set a parameter in the SELECT statement of a SqlDataSource,
in the Page_Load event where the intended value for the parameter is
calculated. But how can I set the parameter to a certain value? If the value
comes from a control, form, querystring etc. then it's easily done
declaratively. But how to do it in code.

Have tried for hours. I will be grateful for all help!
--
Kees de Winter
Mar 29 '06 #1
3 6800
You could do it all programatically , set the SQLDataSource.S electCommand
property and use the SQLDataSource.S electParameter. Add() method to add the
parameter. Alternativley you could use the SQLDataSource.F ilterExpression
and the SQLDataSource.F ilterParameters properties to filter the data after
the fact.

"Kees de Winter" wrote:
Hi,

I am trying to set a parameter in the SELECT statement of a SqlDataSource,
in the Page_Load event where the intended value for the parameter is
calculated. But how can I set the parameter to a certain value? If the value
comes from a control, form, querystring etc. then it's easily done
declaratively. But how to do it in code.

Have tried for hours. I will be grateful for all help!
--
Kees de Winter

Mar 29 '06 #2
If you want to provide a default value for your parameter, and the
param is defined in the aspx file, just do.

protected void Page_Load(objec t sender, EventArgs e)
{
// do page load stuff
SetQueryDefault s();
}

private void SetQueryDefault s()
{
MySqlDataSource .SelectParamete rs["ParameterN ame"].DefaultValue =
MyValue.ToStrin g()
}

Mar 29 '06 #3
That was it! Thanks!!

--
Kees de Winter
"clickon" <cl*****@discus sions.microsoft .com> wrote in message
news:C7******** *************** ***********@mic rosoft.com...
You could do it all programatically , set the SQLDataSource.S electCommand
property and use the SQLDataSource.S electParameter. Add() method to add the
parameter. Alternativley you could use the SQLDataSource.F ilterExpression and the SQLDataSource.F ilterParameters properties to filter the data after
the fact.

"Kees de Winter" wrote:
Hi,

I am trying to set a parameter in the SELECT statement of a SqlDataSource, in the Page_Load event where the intended value for the parameter is
calculated. But how can I set the parameter to a certain value? If the value comes from a control, form, querystring etc. then it's easily done
declaratively. But how to do it in code.

Have tried for hours. I will be grateful for all help!
--
Kees de Winter

Mar 29 '06 #4

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

Similar topics

1
3399
by: realgeek | last post by:
I have the following code: SqlDataSource ds = new SqlDataSource(); ds.ConnectionString = WebConfigurationManager.ConnectionStrings.ToString(); ds.UpdateCommand = "ad_SetAnswer"; ds.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure; ds.UpdateParameters.Add(new Parameter("@QuestionID")); ds.UpdateParameters.Add(new Parameter("@Answer")); foreach (RepeaterItem li in Repeater1.Items)
0
1013
by: ayende | last post by:
I've the following scenario, a web page that dispaly a GridView using SqlDataSource define thus: <asp:SqlDataSource ID="BoardTypes" runat="server" ConnectionString='<%$ ConnectionStrings:ConnectionString %>' SelectCommand="SELECT BoardTypes.BoardTypeId, BoardTypes.BoardTypeName, BoardTypes.BoardTypeDescription, BoardTypes.ValidityEndDate, BoardTypes.ValidityStartDate, OrganizationUnit.Name AS OrganizationalUnitName FROM BoardTypes INNER...
5
4480
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 ControlParameter <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:XYZ %>"
0
2388
by: Mike P | last post by:
Where exactly are the updateparameters of a gridview picked up from? I have created 2 very similar gridviews and given the updateparameters the same names as in my edititemtemplates. Yet this method has worked for 1 gridview and failed for the second gridview. Here is my gridview : <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:XConnectionString %>" SelectCommand="ViewForecast"...
3
8923
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 ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT cedula,nombre,tipo FROM clientes WHERE nombre LIKE '%' + @nombre +...
0
904
by: Steven Blair | last post by:
Here is my problem. This is using a FormView and a SqlDataSource. On Updating, I need to compare the old values (orignal values returned from Database) against the updated values. If there are changes I need to do some processing. The Updating method gives me access to the current variables, but I am unsure how to get hold of the orignal values. If I switch on Optimistic concurrency on my SqlDataSource, the old
3
1350
by: RAR in WA | last post by:
I'm moving to .Net framework 2.0 from Visual Studio 2002/3 with more time on desktop apps than ASP.Net, although I have done a small amount in ASP.Net. Is best practice for ASP.Net now to use the components for data access, or to build your own connection and command objects in code? I find working with the designer to be awkward and hard to follow the details, and would like to know if I really should get used to doing things with...
3
2952
by: djc | last post by:
I am playing with the (new to me) sqlDataSource class. I used it to bind data from a database table into a listbox with no code, worked great. Now I need to do an INSERT for every item in a listbox. I used to just code the ado stuff myself in .net 1.1. For example creating connection object, creating sqlCommand object, parameters, etc... I would just create the ado stuff, then loop through the listbox changing the sqlcommand parameter...
0
1302
by: ADAC | last post by:
I am very familiar with Visual studio 2003 and trying to get a handle on 2005 I can set up the datasource and make it work fine when I databind it to a control like a gridview or details view. Everything is done automatically no programming. I need to take a sqldatasource that I have already created with parameters etc. Set the parameter in the code behind, run it against the database and get the result. in 2003 I would creat a command,...
0
8826
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9316
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8239
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.