I stumbled upon a problem and cannot figure it out myself. Hope someone can help me resolve this.
So, I have a simple stored procedure in a SQL Server 2005 database
CREATE PROCEDURE spTest @pin varchar(128) AS BEGIN SELECT @Pin as Param END
and asp.net page with SqlDataSource
and GridView
controls in the application (VS2008)
<asp:SqlDataSource ID="sds2" runat="server" ConnectionString="..." SelectCommand="spTest" SelectCommandType="StoredProcedure" > <SelectParameters> <asp:QueryStringParameter Name="pin" QueryStringField="pin" DbType="String"/> </SelectParameters> </asp:SqlDataSource> <asp:GridView ID="gv" runat="server" DataSourceID="sds2"></asp:GridView>
As you can see, the code is simple. However, if I donβt specify the PIN on the URL ( .../Default.aspx
instead of .../Default.aspx?pin=somevalue
) or specify an empty string ( .../Default.aspx?pin=
), there is no call to the stored procedure (I check it with SQL Server Profiler).
Moreover, if I replaced QueryStringParameter
with a simple
<asp:Parameter Name="pin" DbType="String" />
and do not specify the value of DefaultValue, the situation repeats, and calls to the stored procedure are not executed. What is the reason for this behavior?
I am new to asp.net and may be missing something, but I even tried to do the same thing in the program code programmatically and not declaratively, and the result is the same. The only thing I could find out was that in this case the Selecting
SqlDataSource
event is Selecting
, but Selected
is not. Maybe some kind of error occurred?
In any case, any help would be greatly appreciated.