Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > SqlDataSource: Changing SelectCommand property before processed

Reply
Thread Tools

SqlDataSource: Changing SelectCommand property before processed

 
 
Martin
Guest
Posts: n/a
 
      03-28-2007
Hi,

I am implementing an SQL repository component. That mean that I want to
overload standard SqlDataSource component and add new property (commandName).
After that, I would like to update the SelectCommand and SelectParameters
properties just before the select is processed (ie. I look into the
repository, find the requested query template, build the text of the query
from the template and update the mentioned properties).

Currently, I have attached on the Selecting event and update the properties
there. Unfortunately, even the property is updated (checked by stepping in
the code), the new value is not used later in the process. Let me show you a
very simplified example. See the source code bellow.

When I run the aspx page, I received the following error, even the
SelectCommand was already changed in the Selecting event (checked by putting
a breakpoint and see the values in the Watch).
Could not find stored procedure 'not used'.

Therefore, I would like to ask you for a help with this issue. Please note
that we really need to update the SelectCommand for each one call of the
query because the command might varry for each particular call (it depends on
the parameters as well).

As a result, my main question is the following:
How to make the code working as expected (ie. how to implement the described
approach)?

Thanks for every tip,

Martin

--- SqlRepositoryDataSource.cs ---

public class SqlRepositoryDataSource :
System.Web.UI.WebControls.SqlDataSource
{
public SqlRepositoryDataSource()
{
Selecting += new
SqlDataSourceSelectingEventHandler(OnSelectingHand ler);
}

protected void OnSelectingHandler(Object source,
SqlDataSourceSelectingEventArgs e)
{
SelectCommand = "Select * from test;";
SelectParameters.Add("a", "b");
}
}

--- DataSourceTest.aspx ---

<cc1:SqlRepositoryDataSource ID="SqlRepositoryDataSource1"
runat="server" CommandTemplateName="system.Framework.test.simple"
ConnectionString="<%$ ConnectionStrings:TestDbConnectionString %>"
SelectCommand="[not used]">
</cc1:SqlRepositoryDataSource>
<asp:GridView ID="GridView1" runat="server"
DataSourceID="SqlRepositoryDataSource1">
</asp:GridView>


 
Reply With Quote
 
 
 
 
Martin
Guest
Posts: n/a
 
      03-28-2007
Hi,

I have finally found that. The event arguments must be changed directly.

Thanks,

Martin

"Martin" wrote:

> Hi,
>
> I am implementing an SQL repository component. That mean that I want to
> overload standard SqlDataSource component and add new property (commandName).
> After that, I would like to update the SelectCommand and SelectParameters
> properties just before the select is processed (ie. I look into the
> repository, find the requested query template, build the text of the query
> from the template and update the mentioned properties).
>
> Currently, I have attached on the Selecting event and update the properties
> there. Unfortunately, even the property is updated (checked by stepping in
> the code), the new value is not used later in the process. Let me show you a
> very simplified example. See the source code bellow.
>
> When I run the aspx page, I received the following error, even the
> SelectCommand was already changed in the Selecting event (checked by putting
> a breakpoint and see the values in the Watch).
> Could not find stored procedure 'not used'.
>
> Therefore, I would like to ask you for a help with this issue. Please note
> that we really need to update the SelectCommand for each one call of the
> query because the command might varry for each particular call (it depends on
> the parameters as well).
>
> As a result, my main question is the following:
> How to make the code working as expected (ie. how to implement the described
> approach)?
>
> Thanks for every tip,
>
> Martin
>
> --- SqlRepositoryDataSource.cs ---
>
> public class SqlRepositoryDataSource :
> System.Web.UI.WebControls.SqlDataSource
> {
> public SqlRepositoryDataSource()
> {
> Selecting += new
> SqlDataSourceSelectingEventHandler(OnSelectingHand ler);
> }
>
> protected void OnSelectingHandler(Object source,
> SqlDataSourceSelectingEventArgs e)
> {
> SelectCommand = "Select * from test;";
> SelectParameters.Add("a", "b");
> }
> }
>
> --- DataSourceTest.aspx ---
>
> <cc1:SqlRepositoryDataSource ID="SqlRepositoryDataSource1"
> runat="server" CommandTemplateName="system.Framework.test.simple"
> ConnectionString="<%$ ConnectionStrings:TestDbConnectionString %>"
> SelectCommand="[not used]">
> </cc1:SqlRepositoryDataSource>
> <asp:GridView ID="GridView1" runat="server"
> DataSourceID="SqlRepositoryDataSource1">
> </asp:GridView>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SelectCommand that does not return any key column information Shenc ASP .Net 3 12-21-2012 03:24 PM
session timeout is processed before the servlet filter? Ken Java 1 01-10-2009 11:23 PM
When user clicks on a link twice before the first click is completely processed.. sapta Java 1 05-24-2007 12:12 PM
spit out SelectCommand G. Whiz ASP .Net 5 03-07-2006 07:50 AM
Change selectcommand on click in aspx.vb prontoo ASP .Net 0 12-13-2005 03:30 PM



Advertisments