0
When I click on "Save", the program does a check of Texbox
with a deal that I did not let pass repeated numbers, the problem is that it error if any Textbox
is blank. Below is the Code I made saving the information in an Excel spreadsheet. As I will not always use Texbox
, how do I make it pass without accusing error in Texbox
blank and send Excel a default value Null
?
if (!string.IsNullOrEmpty(txtCaixa1.Text) && checarString(txtCaixa1.Text))
{
valores[0] = Convert.ToInt64(txtCaixa1.Text);
}
if (!string.IsNullOrEmpty(txtCaixa2.Text) && checarString(txtCaixa2.Text))
{
// usar o link para verificar se existem textBox iguais
if (!valores.Any(v => v.Equals(Convert.ToInt64(txtCaixa2.Text))))
{
valores[1] = Convert.ToInt64(txtCaixa2.Text);
txtCaixa2.BackColor = Color.White;
}
else
{
txtCaixa2.BackColor = Color.Yellow;
messageBoxButtons();
return;
}
}
_oleCmd.CommandText = _Consulta;
_oleCmd.Parameters.Add("@MODELOS", OleDbType.VarChar, 50).Value = txtModelo.Text.Trim();
_oleCmd.Parameters.Add("@QUANTIDADE", OleDbType.VarChar, 255).Value = txtTotalCarton.Text.Trim();
_oleCmd.Parameters.Add("@NUMEROCARTON", OleDbType.Integer).Value = Convert.ToInt32(txtCarton.Text);
_oleCmd.Parameters.Add("@SN1", OleDbType.Integer).Value = Convert.ToInt32(txtCaixa1.Text);
_oleCmd.Parameters.Add("@SN2", OleDbType.Integer).Value = Convert.ToInt32(txtCaixa2.Text);
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site.
– Maniero