Versão do Visual Studio: 2017
Problema: Quero pesquisar um cliente pelo número do celular dele, mas ele não exibe nenhum resultado, a MaskedTextBox usa IncludePromptsandLiterals, eu consigo cadastrar no banco de dados, mas na hora de pesquisar ele não exibe nada.
Código do Erro:
private void mskCel_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
{
string sql = "";
sql = @"select * from clientes where cli_cel like '" + mskCel.Text + "%'";
try
{
conexao.Conectar();
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand(sql, conexao.conn);
dt.Load(cmd.ExecuteReader());
dtgClientes.DataSource = dt;
cod = dtgClientes.CurrentRow.Cells[0].Value.ToString();
nome = dtgClientes.CurrentRow.Cells[1].Value.ToString();
end = dtgClientes.CurrentRow.Cells[2].Value.ToString();
tel = dtgClientes.CurrentRow.Cells[3].Value.ToString();
cel = dtgClientes.CurrentRow.Cells[4].Value.ToString();
dtnas = dtgClientes.CurrentRow.Cells[5].Value.ToString();
}
catch (Exception ex)
{
MessageBox.Show("Registro não encontrado!" + "\n" + "\n" + "Erro: " + ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
conexao.Desconectar();
}
}