By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,289 Members | 3,049 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,289 IT Pros & Developers. It's quick & easy.

how to pass variable to SelectCommand of SqlDataSource?

P: n/a
Hi,

I want to put a recordset in a gridview but i don't know how to pass the
value of the variable in the 'where' statement. The value of the variable is
set in the code-behind. i added a tag <selectParameters> but i don't know
which elements are needed and how...

This is my aspx file:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=c:\mydb.mdb"
ProviderName="System.Data.OleDb"
SelectCommand="SELECT [name], [city] where [name]= @na">
<SelectParameters>
<asp:ControlParameter
Name="??" PropertyName="???" Type="String" ControlID="??" />
</SelectParameters>
</asp:SqlDataSource>

The code-behind contains this:
Public na As String 'i defined it public to be able to pass it to
aspx file ??
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
na = "phil"
End Sub

Thanks for help
Phil
Jun 2 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
If the value of your parameter isn't able to be drawn automatically via one
of the built-in parameter types (like ControlParemeter, QueryStringParameter,
etc) you can always handle the SqlDataSOurce's pre-processing events such
as Selecting, Updating, Deleting and Inserting to manually change or add
a parameter to its SqlCommand.

<script runat="server">
protected void _data_Selecting(object sender, SqlDataSourceSelectingEventArgs
e)
{
e.Command.Parameters["bar"].Value = "oxox";
}
</script>

<asp:SqlDataSource runat="server" ID="_data"
SelectCommand="select * from foo where bar = @bar"
OnSelecting="_data_Selecting">
<SelectParameters>
<asp:Parameter Name="bar" DefaultValue="xoxo" />
</SelectParameters>
</asp:SqlDataSource>
-Brock
http://staff.develop.com/ballen

Hi,

I want to put a recordset in a gridview but i don't know how to pass
the value of the variable in the 'where' statement. The value of the
variable is set in the code-behind. i added a tag <selectParameters>
but i don't know which elements are needed and how...

This is my aspx file:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0 ;Data
Source=c:\mydb.mdb"
ProviderName="System.Data.OleDb"
SelectCommand="SELECT [name], [city] where [name]= @na">
<SelectParameters>
<asp:ControlParameter
Name="??" PropertyName="???" Type="String" ControlID="??" />
</SelectParameters>
</asp:SqlDataSource>
The code-behind contains this:
Public na As String 'i defined it public to be able to pass it
to
aspx file ??
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Handles Me.Load
na = "phil"
End Sub
Thanks for help
Phil

Jun 2 '06 #2

P: n/a
Thanks, it works ...

"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:b8************************@msnews.microsoft.c om...
If the value of your parameter isn't able to be drawn automatically via one of the built-in parameter types (like ControlParemeter, QueryStringParameter, etc) you can always handle the SqlDataSOurce's pre-processing events such
as Selecting, Updating, Deleting and Inserting to manually change or add
a parameter to its SqlCommand.

<script runat="server">
protected void _data_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
e.Command.Parameters["bar"].Value = "oxox";
}
</script>

<asp:SqlDataSource runat="server" ID="_data"
SelectCommand="select * from foo where bar = @bar"
OnSelecting="_data_Selecting">
<SelectParameters>
<asp:Parameter Name="bar" DefaultValue="xoxo" />
</SelectParameters>
</asp:SqlDataSource>
-Brock
http://staff.develop.com/ballen

Hi,

I want to put a recordset in a gridview but i don't know how to pass
the value of the variable in the 'where' statement. The value of the
variable is set in the code-behind. i added a tag <selectParameters>
but i don't know which elements are needed and how...

This is my aspx file:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0 ;Data
Source=c:\mydb.mdb"
ProviderName="System.Data.OleDb"
SelectCommand="SELECT [name], [city] where [name]= @na">
<SelectParameters>
<asp:ControlParameter
Name="??" PropertyName="???" Type="String" ControlID="??" />
</SelectParameters>
</asp:SqlDataSource>
The code-behind contains this:
Public na As String 'i defined it public to be able to pass it
to
aspx file ??
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Handles Me.Load
na = "phil"
End Sub
Thanks for help
Phil


Jun 2 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.