Israel

Israel

  • 699
  • 1.3k
  • 215.6k

Forced to insert code before saving

Nov 14 2016 5:59 AM
Hi!
When I want to save I receive this message. After that its pass to saving process. How can I do to doesnt allow to save without insert the code. Mean before to save its should forced to insert code. How to do it please.
 
if (txtCode.Text == "")
MessageBox.Show("Please insert the code");
 
if (conn.State != ConnectionState.Open)
conn.Open();

//conn.Open();
OleDbCommand comm = new OleDbCommand();
comm.Connection = conn;

connstr = "SELECT COUNT(*) FROM company_anex WHERE [company] = @company";
comm.CommandText = connstr;
comm.Parameters.Clear();
comm.Parameters.AddWithValue("@company", cbxCompanyConfigEmp.Text);

int numRecords = (int)comm.ExecuteScalar();

if (numRecords == 0)
{
connstr = "INSERT INTO company_anex([company])VALUES(company)";
comm.CommandText = connstr;
comm.Parameters.Clear();

comm.Parameters.AddWithValue("@company", cbxCompanyConfigEmp.Text);
comm.ExecuteNonQuery();
MessageBox.Show("Saved ..");
}
conn.Close();

Answers (1)