Server Error in '/ERP' Application. ExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.
protected void btnSave_Click(object sender, EventArgs e) { //lblErrmsg.Text = "Saving.Please wait...."; SqlTransaction transaction; cn.Open(); transaction = cn.BeginTransaction(); try { SqlCommand cmdd = new SqlCommand("BOM_PO_Delete", cn, transaction); cmdd.CommandType = CommandType.StoredProcedure; cmdd.Parameters.AddWithValue("@Styleid", lblStyleid.Text); cmdd.ExecuteNonQuery(); for (int i = 0; i < grdPODtl.Rows.Count; i++) { CheckBox chkselect = (CheckBox)grdPODtl.Rows[i].FindControl("chkselect"); if (chkselect.Checked == true) { Label lbllot = (Label)grdPODtl.Rows[i].FindControl("lbllot"); Label lblqty = (Label)grdPODtl.Rows[i].FindControl("lblqty"); SqlCommand cmddl = new SqlCommand("BOM_PO_Save", cn, transaction); cmddl.CommandType = CommandType.StoredProcedure; cmddl.Parameters.AddWithValue("@Styleid", lblStyleid.Text); cmddl.Parameters.AddWithValue("@Lot", lbllot.Text); cmddl.Parameters.AddWithValue("@qty", lblqty.Text); cmddl.ExecuteNonQuery(); } } SqlCommand cmdd2 = new SqlCommand("BOM_PO_Update", cn, transaction); cmdd2.CommandType = CommandType.StoredProcedure; cmdd2.CommandTimeout = 400; cmdd2.Parameters.AddWithValue("@styleid", lblStyleid.Text); cmdd2.ExecuteNonQuery(); transaction.Commit(); lblErrmsg.Text = "Saved Successfully"; } catch (Exception ex) { lblErrmsg.Text = ex.Message; transaction.Rollback(); } finally { transaction.Dispose(); cn.Close(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)