I am Retrieving data from two table into webform,in which gridview and Textbox ,then again i am trying to inserting data into same table with new ID ,but data is inserting into Master Table ,but not getting insert into Child Table
Here is my Retrieving query
- if (txtRefno.Text == "") {
- Response.Write("<!-- Inject Script Filtered -->");
- } else {
-
- using(SqlCommand cmd = new SqlCommand("[Sp_BalPakinsert]", con)) {
- cmd.CommandType = CommandType.StoredProcedure;
-
- cmd.Parameters.AddWithValue("@Order_Ref_No", txtRefno.Text);
-
- cmd.Parameters.AddWithValue("@OrderNo", txtOrder.Text);
-
- con.Open();
- PID = Convert.ToInt32(cmd.ExecuteScalar());
- con.Close();
-
- DataTable dt = (DataTable) ViewState["dt"];
- int codeitem, qty, orderno, prdno;
-
- foreach(DataRow row in dt.Rows)
-
- {
-
-
- prdno = int.Parse(row["Prdno"].ToString());
- orderno = int.Parse(row["Orderno"].ToString());
- qty = int.Parse(row["QTY"].ToString());
- codeitem = int.Parse(row["Codeitem"].ToString());
-
- this.InsertRows(codeitem, qty, orderno, prdno);
- }
- }
- }
- }
-
- private void InsertRows(int codeitem, int qty, int orderno, int prdno) {
- con.Open();
- using(SqlCommand cmd = new SqlCommand("[SP_BalPakDetail_Insert]", con)) {
-
- cmd.CommandType = CommandType.StoredProcedure;
-
-
- cmd.Parameters.AddWithValue("@PID", PID);
- cmd.Parameters.AddWithValue("@CodeItem", codeitem);
- cmd.Parameters.AddWithValue("@QTY", qty);
- cmd.Parameters.AddWithValue("@Orderno", orderno);
- cmd.Parameters.AddWithValue("@Prdno", prdno);
-
- cmd.ExecuteNonQuery();
-
- con.Close();
- }
- }
- public object PID {
- get;
- set;
- }
- }
-
- }