I am facing this problem since yesterday I tried so many solutions but nothing worked
It keeps telling me the the connection stat is open while I did con.close();
private void cashier_Load(object sender, EventArgs e)
{
int a;
con.Open();
string query = "Select Max (invno) From Invoicesdata";
cmd = new SqlCommand(query, con);
SqlDataReader reader;
reader = cmd.ExecuteReader();
if (reader.Read())
{
string val = reader[0].ToString();
if (val == "")
{
Invoicenm.Text = "1";
}
else
{
a = Convert.ToInt32(reader[0].ToString());
a = a + 1;
Invoicenm.Text = a.ToString();
}
}
con.Close(); //I did connection close but nope
receiptgrid.Rows.Clear();
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
cmd = new SqlCommand("SELECT * FROM Products WHERE Item_Code = @BarCode", con);
cmd.Parameters.Add(new SqlParameter("@BarCode", Productstxt.Text));
con.Open(); //here I am facing the problem
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
foreach (DataGridViewRow row in receiptgrid.Rows)
This is my connection string SqlConnection con =new SqlConnection("Data Source=strongspider.ddns.net;Initial Catalog=POS;Persist Security Info=True;User ID=sa;Password=****Password**"); // <== this is the (POS) Database.