0

Hello all,

I want to use code behind variable in mysql command in aspx file here are the codes

[U]code behind[/U]

public vgroup as string
vgroup ="1,7"

[U]in aspx [/U]

 <asp:SqlDataSource ID="SqlCategoryList" runat="server" 
                ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
                SelectCommand="SELECT * FROM categorymaster WHERE catgroup in ('<%=vgroup %>')"> 
               
            </asp:SqlDataSource>

Thanks.

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by jbisono
0

You can use "SelectParameters" and then add the value of the parameter in the code behind

<asp:SqlDataSource //Instance Properties
SelectCommand="SELECT * FROM categorymaster WHERE catgroup in (@vgroup)">
   <SelectParameters>
      <asp:Parameter Name="vgroup" />
   </SelectParameters>
</asp:SqlDataSource>

then in the background you can do this
sorry this is c# but vb should be very similar

SqlDataSource1.SelectParameters.Clear();
SqlDataSource1.SelectParameters.Add("vgroup", "1,7");

and then bind your DataSource...
Hope that helps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.