I have a small application in C #, which creates the auto-supplier code. I would like to know if anyone knows any way the system can look for an empty code, eg:
1 - Manoel
2 - Narcissus
4 - Mustela
The next code he should pull would be 3 , but he always goes to the last record. Here is the code:
private void btnGravar_Click(object sender, EventArgs e)
{
string Id = txtID.Text;
string Nome = txtNome.Text;
string CNPJ = txtCNPJ.Text;
if (txtNome.Text == "" || txtCNPJ.Text=="" )
{
MessageBox.Show("Favor informar os dados para cadastro!", "Alerta",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
return;
}
try
{
CONEXAO.Open();
comando = new MySqlCommand("INSERT INTO fornecedores (ID, Nome, CNPJ)" + "VALUES ('"
+ Id + "','" + Nome + "','" + CNPJ + "')", CONEXAO);
comando.Parameters.AddWithValue(Id, txtID.Text);
comando.Parameters.AddWithValue(Nome, txtNome.Text);
comando.Parameters.AddWithValue(CNPJ, txtCNPJ.Text);
comando.ExecuteNonQuery();
// Registra os fornecedores no Data Grid.
registraFornecedor(txtID.Text, txtNome.Text, Convert.ToString(txtCNPJ.Text));
ClearControls();
}
catch
{
MessageBox.Show("A conexão com o banco de dados falhou");
}
finally
{
CONEXAO.Close();
}
}