views:

12

answers:

1

I had gridview which retrieve data from database .I did update statement in data ingridview I did my code but when I selected edit option in gridview this error apear (Procedure or Function 'Update_IntoModel' expects parameter '@Id', which was not supplied) .

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        int RowAffected = 0;
        GridView1.EditIndex = e.NewEditIndex;
        using (SqlConnection con = Connection.GetConnection())
        {
            SqlCommand Com = new SqlCommand();
            Com = new SqlCommand("Update_IntoModel", con);
            Com.CommandType = CommandType.StoredProcedure;
            Com.Parameters.Add(Parameter.NewInt("@Id", GridView1.SelectedValue));
            Com.Parameters.Add(Parameter.NewNVarChar("@Model_EN", GridView1.SelectedValue));
            Com.Parameters.Add(Parameter.NewNVarChar("@Model_AR", GridView1.SelectedValue));
            Com.Parameters.Add(Parameter.NewNVarChar("@Url", GridView1.SelectedValue));
            Com.Parameters.Add(Parameter.NewNVarChar("@Resolution_EN", GridView1.SelectedValue));
            Com.Parameters.Add(Parameter.NewNVarChar("@Resolution_AR", GridView1.SelectedValue));
            Com.Parameters.Add(Parameter.NewNVarChar("@Warranty_EN", GridView1.SelectedValue));
            Com.Parameters.Add(Parameter.NewNVarChar("@Warranty_AR", GridView1.SelectedValue));
            Com.Parameters.Add(Parameter.NewNVarChar("@Dimensions_EN", GridView1.SelectedValue));
            Com.Parameters.Add(Parameter.NewNVarChar("@Dimensions_AR", GridView1.SelectedValue));
            Com.Parameters.Add(Parameter.NewNVarChar("@ContrastRatio_EN", GridView1.SelectedValue));
            Com.Parameters.Add(Parameter.NewNVarChar("@ContrastRatio_AR", GridView1.SelectedValue));
            Com.Parameters.Add(Parameter.NewNVarChar("@Brightness_EN", GridView1.SelectedValue));
            Com.Parameters.Add(Parameter.NewNVarChar("@Brightness_AR", GridView1.SelectedValue));
            Com.Parameters.Add(Parameter.NewNVarChar("@PanelResposeSpeed_EN", GridView1.SelectedValue));
            Com.Parameters.Add(Parameter.NewNVarChar("@PanelResposeSpeed_AR", GridView1.SelectedValue));
            Com.Parameters.Add(Parameter.NewBit("@Active", GridView1.SelectedValue));
            RowAffected = Com.ExecuteNonQuery();
            if (RowAffected > 0)
            {
                LblResult.Visible = true;
                LblResult.Text = "Successfully Proccess";
                Update.Visible = false;

            }

        }

<aspx>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
        BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px"
        CellPadding="4" DataKeyNames="Id" ForeColor="Black" GridLines="Vertical" 
        onpageindexchanging="GridView1_PageIndexChanging" 
        onrowediting="GridView1_RowEditing">
        <FooterStyle BackColor="#CCCC99" />
        <RowStyle BackColor="#F7F7DE" />
        <Columns>
            <asp:CommandField HeaderText="Function" ShowEditButton="True" />
            <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True"
                SortExpression="Id" Visible="False" />
            <asp:TemplateField HeaderText="Image">
                <ItemTemplate>
                    <asp:Image ID="Image2" runat="server" ImageUrl='<%#Eval("Id","~/Handlers/Model.ashx?Id={0}") %>' />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Logo">
                <ItemTemplate>
                    <asp:Image ID="Logo" runat="server" ImageUrl='<%#Eval("Id","~/Handlers/ModelLogo.ashx?Id={0}") %>' />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Model_EN" HeaderText="Model_EN" SortExpression="Model_EN" />
            <asp:BoundField DataField="Model_AR" HeaderText="Model_AR" SortExpression="Model_AR" />
            <asp:BoundField DataField="Resolution_EN" HeaderText="Resolution_EN" SortExpression="Resolution_EN" />
            <asp:BoundField DataField="Resolution_AR" HeaderText="Resolution_AR" SortExpression="Resolution_AR" />
            <asp:BoundField DataField="Warranty_EN" HeaderText="Warranty_EN" SortExpression="Warranty_EN" />
            <asp:BoundField DataField="Warranty_AR" HeaderText="Warranty_AR" SortExpression="Warranty_AR" />
            <asp:BoundField DataField="Dimensions_EN" HeaderText="Dimensions_EN" SortExpression="Dimensions_EN" />
            <asp:BoundField DataField="Dimensions_AR" HeaderText="Dimensions_AR" SortExpression="Dimensions_AR" />
            <asp:BoundField DataField="ContrastRatio_EN" HeaderText="ContrastRatio_EN" SortExpression="ContrastRatio_EN" />
            <asp:BoundField DataField="ContrastRatio_AR" HeaderText="ContrastRatio_AR" SortExpression="ContrastRatio_AR" />
            <asp:BoundField DataField="Brightness_EN" HeaderText="Brightness_EN" SortExpression="Brightness_EN" />
            <asp:BoundField DataField="Brightness_AR" HeaderText="Brightness_AR" SortExpression="Brightness_AR" />
            <asp:BoundField DataField="PanelResposeSpeed_EN" HeaderText="PanelResposeSpeed_EN"
                SortExpression="PanelResposeSpeed_EN" />
            <asp:BoundField DataField="PanelResposeSpeed_AR" HeaderText="PanelResposeSpeed_AR"
                SortExpression="PanelResposeSpeed_AR" />
            <asp:BoundField DataField="Url" HeaderText="Url" SortExpression="Url" />
            <asp:BoundField DataField="Accessories_EN" HeaderText="Accessories_EN" InsertVisible="False"
                ReadOnly="True" SortExpression="Accessories_EN" />
            <asp:BoundField DataField="Accessories_AR" HeaderText="Accessories_AR" SortExpression="Accessories_AR"
                InsertVisible="False" ReadOnly="True" />
            <asp:BoundField DataField="Feature_EN" HeaderText="Feature_EN" InsertVisible="False"
                ReadOnly="True" SortExpression="Feature_EN" />
            <asp:BoundField DataField="Feature_AR" HeaderText="Feature_AR" InsertVisible="False"
                ReadOnly="True" SortExpression="Feature_AR" />
            <asp:BoundField DataField="Inputs_EN" HeaderText="Inputs_EN" InsertVisible="False"
                ReadOnly="True" SortExpression="Inputs_EN" />
            <asp:BoundField DataField="Inputs_AR" HeaderText="Inputs_AR" InsertVisible="False"
                ReadOnly="True" SortExpression="Inputs_AR" />
            <asp:BoundField DataField="Technology_EN" HeaderText="Technology_EN" InsertVisible="False"
                ReadOnly="True" SortExpression="Technology_EN" />
            <asp:BoundField DataField="Technology_AR" HeaderText="Technology_AR" InsertVisible="False"
                ReadOnly="True" SortExpression="Technology_AR" />
            <asp:BoundField DataField="Add_Date" HeaderText="Add_Date" SortExpression="Add_Date"
                InsertVisible="False" ReadOnly="True" />
            <asp:CheckBoxField DataField="Active" HeaderText="Active" SortExpression="Active" />
        </Columns>
        <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
        <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
A: 

Check the name of the parameter @Id which may causing error.

also check out the number of parameter you are passing and no of parameter in procedure.

Pranay Rana
This really isn't an answer and should be a comment. I'd think the first point to address would be the passing of `GridView1.SelectedValue` for **every** value to the SQL query.
Lazarus