Hi, there, i have come up with a dropdownlist that takes data from database. A gridview with checkbox to select and a button to submit the selected rows in gridview and selected data in dropdownlist. i am getting errors. I don't know what is the cause. The dropdownlist will have names of delivery boys(designation). At the same time how to only display rows of selected gridview only.
Please help. i have only till 11 am tomorrow. one error encountered at the moment:

Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable "@designation".

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

<form id="form1" runat="server">
    
        <asp:DropDownList ID="DropDownList1" DataSourceID="SqlDataSource2"
        AppendDataBoundItems="true"  DataValueField="Designation" AutoPostBack="true" 
         runat="server" Height="68px" Width="139px">
         </asp:DropDownList>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:CourierSystemConnectionString %>" 
            
            SelectCommand="SELECT [StaffID] FROM [StaffRegis_Table] where designation=@designation">
            
        
        
        </asp:SqlDataSource>
        
         <asp:Label ID="lblname" runat="server"></asp:Label>
        <br />
        <br />
        <br />
        <asp:GridView ID="GridView1" DataSourceID="SqlDataSource1" 
            AutoGenerateColumns="False" AutoGenerateEditButton="True"  runat="server" 
            AllowPaging="True">
        
        <Columns>
        <asp:TemplateField HeaderText="Check"> 

    <HeaderTemplate> 

        <asp:CheckBox ID="chkAll" runat="server" 

            onclick = "checkAll(this);" /> 

    </HeaderTemplate> 

    <ItemTemplate> 

        <asp:CheckBox ID="CheckBox1" runat="server"  Text="check"

            onclick = "Check_Click(this)"/> 

    </ItemTemplate> 

</asp:TemplateField> 


        
        
        

        <asp:BoundField ItemStyle-Width = "150px"  ReadOnly="true" SortExpression="CusID"

    DataField = "CusID" HeaderText = "Customer ID" > 

<ItemStyle Width="150px"></ItemStyle>
            </asp:BoundField>

<asp:BoundField ItemStyle-Width = "150px" 

    DataField = "CusFName" HeaderText = "First Name"> 

<ItemStyle Width="150px"></ItemStyle>
            </asp:BoundField>

<asp:BoundField ItemStyle-Width = "150px" 

    DataField = "CusLName" HeaderText = "Last Name"> 

<ItemStyle Width="150px"></ItemStyle>
            </asp:BoundField>

<asp:BoundField ItemStyle-Width = "150px" 

    DataField = "Address" HeaderText = "Address"> 
<ItemStyle Width="150px"></ItemStyle>
            </asp:BoundField>
<asp:BoundField ItemStyle-Width = "150px" 

    DataField = "City" HeaderText = "City"> 
<ItemStyle Width="150px"></ItemStyle>
            </asp:BoundField>
    <asp:BoundField ItemStyle-Width = "150px" 

    DataField = "State" HeaderText = "State">
     
<ItemStyle Width="150px"></ItemStyle>
            </asp:BoundField>
     
    <asp:BoundField ItemStyle-Width = "150px" 

    DataField = "HP_Num" HeaderText = "HP_Num">
    
<ItemStyle Width="150px"></ItemStyle>
            </asp:BoundField>
    
    <asp:BoundField ItemStyle-Width = "150px" 

    DataField = "receiver" HeaderText = "Receiver Name">
<ItemStyle Width="150px"></ItemStyle>
            </asp:BoundField>
    <asp:BoundField ItemStyle-Width = "150px" 

    DataField = "Address1" HeaderText = "Address">
<ItemStyle Width="150px"></ItemStyle>
            </asp:BoundField>
    <asp:BoundField ItemStyle-Width = "150px" 

    DataField = "Poscode" HeaderText = "Poscode">
<ItemStyle Width="150px"></ItemStyle>
            </asp:BoundField>
    <asp:BoundField ItemStyle-Width = "150px" 

    DataField = "City1" HeaderText = "City">
    
<ItemStyle Width="150px"></ItemStyle>
            </asp:BoundField>
    
    <asp:BoundField ItemStyle-Width = "150px" 

    DataField = "State1" HeaderText = "State">
<ItemStyle Width="150px"></ItemStyle>
            </asp:BoundField>
    <asp:BoundField ItemStyle-Width = "150px" 

    DataField = "Contact_Num" HeaderText = "Contact Number">
    
    
    
        
        
<ItemStyle Width="150px"></ItemStyle>
            </asp:BoundField>
    
    
    
        
        
        </Columns>
        </asp:GridView>
        
        
         <asp:Button ID="Button2" runat="server" Text="Assign" />
         
    
        
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CourierSystemConnectionString %>" 
        
        UpDateCommand="UpDate PickUp_CusRegis_Table Set CusID=@CusID, CusFName=@CusFName, CusLName=@CusLName, City=@City, Address=@Address, State=@State,HP_Num=@HP_Num, Receiver=@Receiver, Address1=@Address1, City1=City1, State1=@State1, Contact_Num=@Contact_Num, Poscode=@Poscode where CusID=@CusID"
        OldValuesParameterFormatString="original_{0}"
        SelectCommand="SELECT [CusID], [CusFName], [CusLName], [Password2], [RetypePass2], [Address], [City], [State], [HP_Num], [Fax_Num], [Receiver], [Address1], [City1], [State1], [Contact_Num], [Poscode] FROM [PickUp_CusRegis_Table]">
        <FilterParameters>
                <asp:ControlParameter Name="CusID" ControlID="DropDownList1" PropertyName="SelectedValue" />
            </FilterParameters>
         <UpDateParameters>
                <asp:Parameter Name="CusID" Type="String" />
                <asp:Parameter Name="CusFName" Type="String" />
                <asp:Parameter Name="CusLName" Type="String" />
                <asp:Parameter Name="Password2" Type="String" />
                <asp:Parameter Name="RetypePass2" Type="String" />
                <asp:Parameter Name="Role" Type="String" />
                <asp:Parameter Name="Address" Type="String" />
               
                <asp:Parameter Name="City" Type="String" />
                <asp:Parameter Name="State" Type="String" />
                <asp:Parameter Name="HP_Num" Type="string" />
                <asp:Parameter Name="Fax_Num" Type="string" />
               
            </UpDateParameters>
        </asp:SqlDataSource>
   


    
    
    
        


    </form>

Recommended Answers

All 3 Replies

From where are you supposed to provide the value for Where condition i.e @designation for the SqlDataSource of DropDownlist. Giive it a thought.

I am online now, i can help you immediately.


and what do you mean by statement "At the same time how to only display rows of selected gridview only." Please be precise.

First solve your problem of "Must declare the scalar variable "@designation"" and then we will look at the other problem.

The @designation is actually a column in the database. it stores the delivery boy and manager roles. i need to just take the delivery boy names and show on the dropdownlist.

Then i guess you have written wrong SQL Statement to extract the deliveryboy names in this part of the code as you have written:

SelectCommand="SELECT [StaffID] FROM [StaffRegis_Table] where designation=@designation">

but it should be written as below:

SelectCommand="SELECT [StaffID] FROM [StaffRegis_Table] where designation='deliveryboy'">

All i want to say is that you are using a parameter "@designation" to be passed the sqlstatement. Don't do that, directly pass the value to the "designation" of where condition as shown above in my code suggestion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.