Column 'QTY' does not belong to table .
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Column 'QTY' does not belong to table .
namespace Jewelleryonlineshop
{
public partial class Shoppingcart : System.Web.UI.Page
{
int IPID = 0;
SqlConnection con = new SqlConnection("Data Source=.;Integrated Security=true;Initial Catalog=Shoppingcart;");
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt;
dt = (DataTable)Session["buyitems"];
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void Save_Click(object sender, EventArgs e)
{
con.Open();
// int _PID = 0;
using (SqlCommand cmd = new SqlCommand("Masterinsert", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", txtName.Text);
cmd.Parameters.AddWithValue("@Address", txtaddress.Text);
cmd.Parameters.AddWithValue("@Phone", txtPhone.Text);
cmd.Parameters.AddWithValue("@EmailAdress", txtEmail.Text);
_PID = Convert.ToInt32(cmd.ExecuteScalar());
//con.Close();
DataTable dt = (DataTable)Session["buyitems"];
int codeitem, qty;
foreach (DataRow row in dt.Rows)
{
//pid = int.Parse(row["_PID"].ToString());
qty = int.Parse(row["txtQty"].ToString());
codeitem = int.Parse(row["SellId"].ToString());
this.InsertRows(codeitem, qty);
}
}
}
private void InsertRows(int codeitem, int qty)
{
con.Open();
using (SqlCommand cmd = new SqlCommand("Insert_Detail", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ID", _PID);
cmd.Parameters.AddWithValue("@SellId", codeitem);
cmd.Parameters.AddWithValue("@QTY", qty);
cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
Line 64: //pid = int.Parse(row["_PID"].ToString());
Line 65:
Line 66: qty = int.Parse(row["QTY"].ToString());
Line 67: codeitem = int.Parse(row["SellId"].ToString());
Line 68: