Israel

Israel

  • 702
  • 1.3k
  • 215.8k

I need to save with a simple condition

Mar 4 2016 12:00 AM
Hi!
 
I have on my form one label (lblMsgSend) with the text "Sended". I need with these codes when there datas that already exist it cant show this label's message "Sended".
Right now when I click to my save's button (even it found datas already exist its show the label's message) . How can I do please.
 
conn.Open();
OleDbCommand comm = new OleDbCommand();
comm.Connection = conn;
connstr = "SELECT COUNT(*) FROM propTrans WHERE [nome] = @nome";
comm.CommandText = connstr;
comm.Parameters.Clear();
comm.Parameters.AddWithValue("@nome", cbxNomePropinas.Text);
comm.Parameters.AddWithValue("@tipopagamento", cbxTipoPagamentoPropinas.Text);
comm.Parameters.AddWithValue("@mes", cbxMesPropinas.Text);
int numRecords = (int)comm.ExecuteScalar();
if (numRecords == 0)
{
connstr = "INSERT INTO propTrans([nome],[tipopagamento],[mes])VALUES(@nome,@tipopagamento,@mes)";
comm.CommandText = connstr;
comm.Parameters.Clear();
comm.Parameters.AddWithValue("@nome", cbxNomePropinas.Text);
comm.Parameters.AddWithValue("@tipopagamento", cbxTipoPagamentoPropinas.Text);
comm.Parameters.AddWithValue("@mes", cbxMesPropinas.Text);
comm.ExecuteNonQuery();
conn.Close();
/////////////////////////////////////////////////////////////////////////////////
timer1.Start();
lblMsgSend.Visible = true;

Answers (7)