473,404 Members | 2,170 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,404 software developers and data experts.

Modify SqlDataSource parameters before select

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 %>"
SelectCommand="myStoredProcedure"
SelectCommandType="storedProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="txtTitle" Name="Title"
PropertyName="Text" Type="String" DefaultValue="%" />
</SelectParameters>
</asp:SqlDataSource>

What I'd like to do is to modify the value of the Title parameter before the
select command is executed. E.g. if the user enters "abc*" in txtTitle, I'd
like to change the parameter's value to "abc%".

Thanks for any help,
Martin
Nov 19 '05 #1
5 4452
Hi Martine,

Welcome to ASPNET newsgroup.
As for the modifying SqlDataSource's parameters before the select command
actually get executed, we can utilize the
SqlDataSource control's "Selecting" event, this event get fired before the
actual execute command being executed. the event will have a
SqlDataSourceSelectingEventArgs paramter passed in which can help us
access the paramters used to perform the select comand:

protected void SqlDataSource1_Selecting(object sender,
SqlDataSourceSelectingEventArgs e)
{

}

In fact, in asp.net 2.0 , all the datasource controls support some buildin
pre/post processsing events such as
"selecting/selected", "updating/updated"..... which get fired before/after
a certain command executing.

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: Modify SqlDataSource parameters before select
| thread-index: AcXVY3bXKFhY+ZLJTQeWe1aVqsr9nA==
| X-WBNR-Posting-Host: 194.209.202.1
| From: =?Utf-8?B?TWFydGluIEJpc2Nob2Zm?= <ni******@newsgroup.nospam>
| Subject: Modify SqlDataSource parameters before select
| Date: Thu, 20 Oct 2005 03:46:02 -0700
| Lines: 24
| Message-ID: <A7**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:132687
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| 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 %>"
| SelectCommand="myStoredProcedure"
| SelectCommandType="storedProcedure">
| <SelectParameters>
| <asp:ControlParameter ControlID="txtTitle" Name="Title"
| PropertyName="Text" Type="String" DefaultValue="%" />
| </SelectParameters>
| </asp:SqlDataSource>
|
| What I'd like to do is to modify the value of the Title parameter before
the
| select command is executed. E.g. if the user enters "abc*" in txtTitle,
I'd
| like to change the parameter's value to "abc%".
|
| Thanks for any help,
| Martin
|

Nov 19 '05 #2
Hi Steven,
thanks for your reply. In fact, what you describe is exactly what I have
done so far. But how to continue from there, how do I access and modify the
SqlDataSource's parameter values? I have not found any documentation / sample
about that.

Martin Bischoff
"Steven Cheng[MSFT]" wrote:
Hi Martin,

Welcome to ASPNET newsgroup.
As for the modifying SqlDataSource's parameters before the select command
actually get executed, we can utilize the
SqlDataSource control's "Selecting" event, this event get fired before the
actual execute command being executed. the event will have a
SqlDataSourceSelectingEventArgs paramter passed in which can help us
access the paramters used to perform the select comand:

protected void SqlDataSource1_Selecting(object sender,
SqlDataSourceSelectingEventArgs e)
{

}

In fact, in asp.net 2.0 , all the datasource controls support some buildin
pre/post processsing events such as
"selecting/selected", "updating/updated"..... which get fired before/after
a certain command executing.

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: Modify SqlDataSource parameters before select
| thread-index: AcXVY3bXKFhY+ZLJTQeWe1aVqsr9nA==
| X-WBNR-Posting-Host: 194.209.202.1
| From: =?Utf-8?B?TWFydGluIEJpc2Nob2Zm?= <ni******@newsgroup.nospam>
| Subject: Modify SqlDataSource parameters before select
| Date: Thu, 20 Oct 2005 03:46:02 -0700
| Lines: 24
| Message-ID: <A7**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:132687
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| 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 %>"
| SelectCommand="myStoredProcedure"
| SelectCommandType="storedProcedure">
| <SelectParameters>
| <asp:ControlParameter ControlID="txtTitle" Name="Title"
| PropertyName="Text" Type="String" DefaultValue="%" />
| </SelectParameters>
| </asp:SqlDataSource>
|
| What I'd like to do is to modify the value of the Title parameter before
the
| select command is executed. E.g. if the user enters "abc*" in txtTitle,
I'd
| like to change the parameter's value to "abc%".
|
| Thanks for any help,
| Martin
|

Nov 19 '05 #3
Thanks for your response Martin,

So in SqlDataSource's "Updating" event, we can access the parameters
through the SqlDataSourceEventArg 's

Command.Parameters collection. For example:

protected void SqlDataSource1_Updating(object sender,
SqlDataSourceCommandEventArgs e)
{
Response.Write("<br>CommandType: " + e.Command.CommandType);
Response.Write("<br>Commandparammeters: " + e.Command.Parameters.Count);
foreach (DbParameter param in e.Command.Parameters)
{
Response.Write("<br>" + param.ParameterName + ": " + param.Value);
}

e.Cancel = true;
}

Also, for intercepting the updating or deleting operation and do our
customziation, I'd suggest you consider do it at databound control level
instead of at datasource level as much as possible. Because the DataBound
controls also provide some certain data accessing related pre/post
processing events such as GridView's RowUpdating/RowUpdated , Formview's
ItemUpdating/ItemUpdated .... and they're more easiser to use then
DataSource control's events.

e.g.
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs
e)
{
//e.Keys;

//e.NewValues;

//e.OldValues;
}
Hope also helps. thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: Modify SqlDataSource parameters before select
| thread-index: AcXWDTPeMZdfCKCyT8unaRTKrcH8lw==
| X-WBNR-Posting-Host: 194.209.202.1
| From: =?Utf-8?B?TWFydGluIEJpc2Nob2Zm?= <ni******@newsgroup.nospam>
| References: <A7**********************************@microsoft.co m>
<o$**************@TK2MSFTNGXA01.phx.gbl>
| Subject: RE: Modify SqlDataSource parameters before select
| Date: Fri, 21 Oct 2005 00:01:04 -0700
| Lines: 97
| Message-ID: <49**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:132958
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi Steven,
| thanks for your reply. In fact, what you describe is exactly what I have
| done so far. But how to continue from there, how do I access and modify
the
| SqlDataSource's parameter values? I have not found any documentation /
sample
| about that.
|
| Martin Bischoff
|
|
| "Steven Cheng[MSFT]" wrote:
|
| > Hi Martin,
| >
| > Welcome to ASPNET newsgroup.
| > As for the modifying SqlDataSource's parameters before the select
command
| > actually get executed, we can utilize the
| > SqlDataSource control's "Selecting" event, this event get fired before
the
| > actual execute command being executed. the event will have a
| > SqlDataSourceSelectingEventArgs paramter passed in which can help us
| > access the paramters used to perform the select comand:
| >
| > protected void SqlDataSource1_Selecting(object sender,
| > SqlDataSourceSelectingEventArgs e)
| > {
| >
| > }
| >
| > In fact, in asp.net 2.0 , all the datasource controls support some
buildin
| > pre/post processsing events such as
| > "selecting/selected", "updating/updated"..... which get fired
before/after
| > a certain command executing.
| >
| > Hope helps. Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| > --------------------
| > | Thread-Topic: Modify SqlDataSource parameters before select
| > | thread-index: AcXVY3bXKFhY+ZLJTQeWe1aVqsr9nA==
| > | X-WBNR-Posting-Host: 194.209.202.1
| > | From: =?Utf-8?B?TWFydGluIEJpc2Nob2Zm?= <ni******@newsgroup.nospam>
| > | Subject: Modify SqlDataSource parameters before select
| > | Date: Thu, 20 Oct 2005 03:46:02 -0700
| > | Lines: 24
| > | Message-ID: <A7**********************************@microsoft.co m>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 7bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:132687
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | 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 %>"
| > | SelectCommand="myStoredProcedure"
| > | SelectCommandType="storedProcedure">
| > | <SelectParameters>
| > | <asp:ControlParameter ControlID="txtTitle" Name="Title"
| > | PropertyName="Text" Type="String" DefaultValue="%" />
| > | </SelectParameters>
| > | </asp:SqlDataSource>
| > |
| > | What I'd like to do is to modify the value of the Title parameter
before
| > the
| > | select command is executed. E.g. if the user enters "abc*" in
txtTitle,
| > I'd
| > | like to change the parameter's value to "abc%".
| > |
| > | Thanks for any help,
| > | Martin
| > |
| >
| >
|

Nov 19 '05 #4
Thanks Steven, this was the information I was looking for.

Best regards,
Martin

"Steven Cheng[MSFT]" wrote:
Thanks for your response Martin,

So in SqlDataSource's "Updating" event, we can access the parameters
through the SqlDataSourceEventArg 's

Command.Parameters collection. For example:

protected void SqlDataSource1_Updating(object sender,
SqlDataSourceCommandEventArgs e)
{
Response.Write("<br>CommandType: " + e.Command.CommandType);
Response.Write("<br>Commandparammeters: " + e.Command.Parameters.Count);
foreach (DbParameter param in e.Command.Parameters)
{
Response.Write("<br>" + param.ParameterName + ": " + param.Value);
}

e.Cancel = true;
}

Also, for intercepting the updating or deleting operation and do our
customziation, I'd suggest you consider do it at databound control level
instead of at datasource level as much as possible. Because the DataBound
controls also provide some certain data accessing related pre/post
processing events such as GridView's RowUpdating/RowUpdated , Formview's
ItemUpdating/ItemUpdated .... and they're more easiser to use then
DataSource control's events.

e.g.
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs
e)
{
//e.Keys;

//e.NewValues;

//e.OldValues;
}
Hope also helps. thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Nov 19 '05 #5
You're welcome Martin,

Best Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| Thread-Topic: Modify SqlDataSource parameters before select
| thread-index: AcXYotCCpDtRXFvJSf2plq1QOZvQ+w==
| X-WBNR-Posting-Host: 194.209.202.1
| From: =?Utf-8?B?TWFydGluIEJpc2Nob2Zm?= <ni******@newsgroup.nospam>
| References: <A7**********************************@microsoft.co m>
<o$**************@TK2MSFTNGXA01.phx.gbl>
<49**********************************@microsoft.co m>
<b5**************@TK2MSFTNGXA01.phx.gbl>
| Subject: RE: Modify SqlDataSource parameters before select
| Date: Mon, 24 Oct 2005 06:57:04 -0700
| Lines: 60
| Message-ID: <09**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA02.phx.gbl!TK2MSF TNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:133435
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks Steven, this was the information I was looking for.
|
| Best regards,
| Martin
|
| "Steven Cheng[MSFT]" wrote:
|
| > Thanks for your response Martin,
| >
| > So in SqlDataSource's "Updating" event, we can access the parameters
| > through the SqlDataSourceEventArg 's
| >
| > Command.Parameters collection. For example:
| >
| > protected void SqlDataSource1_Updating(object sender,
| > SqlDataSourceCommandEventArgs e)
| > {
| > Response.Write("<br>CommandType: " + e.Command.CommandType);
| > Response.Write("<br>Commandparammeters: " +
e.Command.Parameters.Count);
| > foreach (DbParameter param in e.Command.Parameters)
| > {
| > Response.Write("<br>" + param.ParameterName + ": " + param.Value);
| > }
| >
| > e.Cancel = true;
| > }
| >
| >
| >
| > Also, for intercepting the updating or deleting operation and do our
| > customziation, I'd suggest you consider do it at databound control
level
| > instead of at datasource level as much as possible. Because the
DataBound
| > controls also provide some certain data accessing related pre/post
| > processing events such as GridView's RowUpdating/RowUpdated ,
Formview's
| > ItemUpdating/ItemUpdated .... and they're more easiser to use then
| > DataSource control's events.
| >
| > e.g.
| > protected void GridView1_RowUpdating(object sender,
GridViewUpdateEventArgs
| > e)
| > {
| > //e.Keys;
| >
| > //e.NewValues;
| >
| > //e.OldValues;
| > }
| >
| >
| > Hope also helps. thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
|
|

Nov 19 '05 #6

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

Similar topics

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...
2
by: Dabbler | last post by:
I have a TextBox used to enter a search value and a DropDownList used to select which field should be searched on. I need to load a GridView with the search results. I have setup multiple select...
0
by: Giovanni | last post by:
I was wondering if someone would be able to help me with the following: Simply put, I have built an ASP.NET 2.0 WebUserControl (UC1). UC1 contains: A GridView which is bound to an SQLDataSource...
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...
0
by: JR | last post by:
I have a question with SqlDataSource controls. I have a SqlDataSource control that has a select, insert and update parameters defined. This is running with Visual Studio 2005 Team system and Net...
6
by: Ken Fine | last post by:
I'm using SQLDataSource, which generates some kind of dataset, and then I attach that datasource to various data display controls such as DataList and repeater which loop through to the end of the...
2
by: Brad Isaacs | last post by:
Good evening friends, I have added a Drop Down List box control to my web form. I am using the web.config connection string to access my SQL Server 2000 db. Inside that db I have a table named...
1
by: John Bailo | last post by:
This is a my solution to getting an Output parameter from a SqlDataSource. I have seen a few scant articles but none of them take it all the way to a solution. Hopefully this will help some...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
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,...
0
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...
0
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...
0
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,...

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.