-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();
}
}
}