troubleshooting Question

SqlDataSource1.SelectParamenters.add("@FirstName", "John"). Must declare the scalar variable "@FirstName".

Avatar of dejandejanovic
dejandejanovic asked on
2 Comments1 Solution461 ViewsLast Modified:
I'm trying to change SqlDataSource control behind code, in, with Button. But just cannot get throught problem 'Must declare the scalar'. I was reading so many topics, but just cannot get results. code:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<br />
<asp:DropDownList ID="DropDownListFirstName" runat="server">
<br />
<asp:DropDownList ID="DropDownListSecondName" runat="server">
<br />
<asp:DropDownList ID="DropDownListTown" runat="server">
    <asp:ListItem>New York</asp:ListItem>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
        EmptyDataText="There are no data records to display.">
            <asp:BoundField DataField="FirstName" HeaderText="FirstName" 
                SortExpression="FirstName" />
            <asp:BoundField DataField="SecondName" HeaderText="SecondName" 
                SortExpression="SecondName" />
            <asp:BoundField DataField="Town" HeaderText="Town" SortExpression="Town" />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:database21ConnectionString %>"
        SelectCommand="SELECT [FirstName], [SecondName], [Town] FROM [test]">
</form> code:
Imports System.Data
Imports System.Data.SqlClient
Partial Class zest
    Inherits System.Web.UI.Page
    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        SqlDataSource1.SelectCommand = "Select * From test Where FirstName = @FirstName"
        SqlDataSource1.SelectParameters.Add("@FirstName", "John")
    End Sub
End Class

Thanks in advance for help!
Easwaran Paramasivam
Senior Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros