I am doing a webform in asp.net and I want to display a gridview with data from asp: SqlDataSource
My problem occurs when I try to skip (pass null) values ββfor some parameters.
Here are some snippets of my code
In an aspx file, sqldatasource looks like
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" SelectCommand="art_bat_art" SelectCommandType="StoredProcedure"> <SelectParameters> <asp:Parameter Name="art_naz" DefaultValue="HLA" ConvertEmptyStringToNull="true" Type="String" /> <asp:Parameter Name="art_sifra" DbType="String" Direction="Input"/> <asp:Parameter Name="vrsta_id" DefaultValue="3" ConvertEmptyStringToNull="true" Type="Int32" /> <asp:Parameter Name="podvrsta_id" DefaultValue="13" ConvertEmptyStringToNull="true" Type="Int32" /> <asp:Parameter Name="podgrupa2" DefaultValue="1365" ConvertEmptyStringToNull="true" Type="Int32" /> <asp:Parameter Name="podosobine" DefaultValue="1:9241" ConvertEmptyStringToNull="true" Type="String" /> <asp:Parameter Name="podosobineOR" DefaultValue="true" ConvertEmptyStringToNull="true" Type="Boolean" /> </SelectParameters>
My grid is as follows:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1">
And problems arise in the code. One of the parameters for my stored procedure is optional; if I pass it as null in SQL, the stored procedure will still be executed.
I am trying to skip this parameter as follows
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click1(object sender, EventArgs e) { SqlDataSource1.SelectParameters["art_sifra"].DefaultValue = DBNull.Value;
source share