Still in the newbie stage and have a project at work. I've searched google and read till my eye's have bleed. There has to be something small I'm overlooking. I'm needing to pass a variable "dNum" into the SQL query. If I don't put in the "SelectParameters" it'll tell me I need to declare the scalar variable, which makes sense. I can't get it to pick up the variable.. the default value does work.
Any pointers? Thanks in advance.
<asp:TextBox ID="dNumber" runat="server"></asp:TextBox><asp:Button ID="Button1" runat="server" Text="Go!" OnClick="runQuery" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Door_Clearance %>"
SelectCommand="SELECT a.Name, c.Name, c.Description
FROM [SWHSystem].[dbo].[Door] AS a
JOIN [SWHSystem].[dbo].[ClearanceItem] AS b ON a.ObjectID=b.DoorID
JOIN [SWHSystem].[dbo].[Clearance] AS c ON b.ClearanceID=c.ObjectID
WHERE a.Name LIKE @dNum1">
<SelectParameters> <asp:SessionParameter Name="dNum1"
SessionField="dNum"
DefaultValue='%1500%'/></SelectParameters>
</asp:SqlDataSource>
In the .cs file..
protected void runQuery(object sender, EventArgs e)
{
string dNum = "'%" + dNumber.Text + "%'";
//SqlDataSource1.SelectParameters.Add("dNum1", dNum);
SqlDataSource1.SelectParameters["dNum1"].DefaultValue = "dNum";
}
ControlParameterinstead and have it reference thedNumbercontrol. Currently you are using aSessionParameterwhich will try to fetch yhe value from theSession.