M
Martin
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(OnSelectingHandler);
}
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>
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(OnSelectingHandler);
}
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>