when i am trying to insert master table id into child table then this error is coming that
No mapping exists from object type System.Web.UI.WebControls.TextBox to a known managed provider native type.)
on this line
_PID = Convert.ToInt32(cmd.ExecuteScalar());
here is inserting code into DB
protected void Save_Click(object sender, EventArgs e)
{
int _PID = 0;
using (SqlCommand cmd = new SqlCommand("Insert_Pack", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@PID", IPID);
cmd.Parameters.AddWithValue("@PName", txtName);
con.Open();
_PID = Convert.ToInt32(cmd.ExecuteScalar());
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))
{
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@PID", _PID );
cmd.Parameters.AddWithValue("@CodeItem", codeitem);
cmd.Parameters.AddWithValue("@QTY", qty);
cmd.ExecuteNonQuery();
con.Close();
}
}
public object _PID { get; set; }
}