-1
如何解決此錯誤如何解決此錯誤「連接未關閉,連接的當前狀態已打開。」
連接未關閉。連接的當前狀態已打開。
雖然我收我的下面這段代碼連接,想盡一切辦法,甚至關閉
private void cmbdealercode_SelectedIndexChanged(object sender, EventArgs e)
{
if (txtinvoiceno.Text == "")
{
if (txtinvoicedate.Text == "")
{
con.Open();
SqlCommand cmd1 = new SqlCommand("select * from tbl_invoice where invoice_no = @no,[email protected],[email protected]", con);
cmd1.Parameters.AddWithValue("@no", txtinvoiceno.Text);
cmd1.Parameters.AddWithValue("@date", txtinvoicedate.Text);
cmd1.Parameters.AddWithValue("@dealercode", cmbdealercode.SelectedValue);
SqlDataAdapter adpt = new SqlDataAdapter(cmd1);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
adpt.Fill(dt);
if (dt.Rows.Count > 0)
{
MessageBox.Show("Already invoice has done for the concern details");
lblpaymentstatus.Text = "";
lbluntilpaid.Text = "";
lblpaymentstatus.Text = dt.Rows[0]["invoice_payment_status"].ToString();
lbluntilpaid.Text = dt.Rows[0]["so_far_paid"].ToString();
}
else
{
DialogResult dialogueresult = MessageBox.Show("The entered details are seems to be new; your new invoice will be raised", "The Question", MessageBoxButtons.OK);
lblpaymentstatus.Text = "Not Paid";
lbluntilpaid.Text = "0";
}
con.Close();
}
}
}