Insert ASP.Net GridView data to Database Error: Column Codeitem does not belong to table Table1

Last Reply one year ago By pandeyism

Posted one year ago

When i am inserting data from gridview to database then exception is coming that 

(Column 'Codeitem' does not belong to table Table1.)

i am trying to insert codeitem into database not description of item 

here is my code of inserting data into table.

//Save Data Into Gridview//
protected void GVadd_Click(object sender, EventArgs e)
    dt = ViewState["dt"] as DataTable;
    dr = dt.NewRow();
    //  dr["Codeitem"] = DropDownList1.SelectedValue;
    dr["Descriptionitem"] = DropDownList1.SelectedItem.Text.Trim();

    dr["QTY"] = txtqty.Text;
    GridView1.DataSource = dt;

private void clear()
    // Codeitem.Text = "";
    txtqty.Text = "";

//Save Data into Database//
protected void Save_Click(object sender, EventArgs e)
    DataTable dt = (DataTable)ViewState["dt"];
    int codeitem, qty;

    foreach (DataRow row in dt.Rows)
        qty = int.Parse(row["QTY"].ToString());
        codeitem = int.Parse(row["Codeitem"].ToString());
        this.InsertRows(codeitem, qty);

private void InsertRows(int codeitem, int qty)
    using (SqlCommand cmd = new SqlCommand("Insert_PackDetail", con))
        cmd.CommandType = CommandType.StoredProcedure;
        // cmd.Parameters.AddWithValue("@PID", pid);
        cmd.Parameters.AddWithValue("@CodeItem", codeitem);
        cmd.Parameters.AddWithValue("@QTY", qty);



This question does not have replies that have been liked.