我下面有这段代码,用于将gridview,文本框和下拉列表中的某些值插入到sql表中。当我单击保存时,它不会插入任何记录,并且不会生成任何错误。欢迎找出问题所在的任何帮助
这是代码
protected void BtnSave_Click(object sender, EventArgs e)
{
int CustomerID = int.Parse(CSID.Value);
int UserID = Convert.ToInt32(Session["UserID"]);
int ModeID = int.Parse(DdlMode.SelectedValue);
string ManualRec = TxtReceipt.Text;
string Ref = Convert.ToString(Session["BreakNum"]);
float Amount = float.Parse(TxtAmount.Text);
foreach (GridViewRow row in GrdLedger.Rows)
{
int LedgerID = Convert.ToInt32(row.Cells[0].Text);
double LedgerAmount = Convert.ToDouble(row.Cells[2].Text);
if (MyCon.State.ToString() == "Closed") { MyCon.Open(); }
using (SqlCommand command = new SqlCommand("insert into TPayments(CustomerID,UserID,ModeID,LedgerID,ManualRec,Ref,Amount,LedgerAmount)values(@CustomerID,@UserID,@ModeID,@LedgerID,@ManualRec,@Ref,@Amount,@LedgerAmount)", MyCon))
{
command.Parameters.AddWithValue("@CustomerID", CustomerID);
command.Parameters.AddWithValue("@UserID", UserID);
command.Parameters.AddWithValue("@ModeID", ModeID);
command.Parameters.AddWithValue("@LedgerID", LedgerID);
command.Parameters.AddWithValue("@ManualRec", ManualRec);
command.Parameters.AddWithValue("@Ref", Ref);
command.Parameters.AddWithValue("@Amount", Amount);
command.Parameters.AddWithValue("@LedgerAmount", LedgerAmount);
command.ExecuteNonQuery();
}
}
MyCon.Close();
}