people, every time I try to compile this statement, an error appears saying Specified cast is not valid.
how can I solve?
MySqlConnection sqlconn = null;
private string strconn = @"Server=localhost; User Id=root; DataBase=betagames";
private string _sql = string.Empty;
public Login()
{
InitializeComponent();
}
public void logar()
{
sqlconn = new MySqlConnection(strconn);
string usu, pwd;
txtusuario.Focus();
try
{
usu = txtusuario.Text;
pwd = txtsenha.Text;
_sql = "select count(coduser) from usuário where usuario = @usuario and senha = @senha";
MySqlCommand cmd = new MySqlCommand(_sql, sqlconn);
cmd.Parameters.Add("@usuario", MySqlDbType.VarChar).Value = usu;
cmd.Parameters.Add("@senha", MySqlDbType.VarChar).Value = pwd;
sqlconn.Open();
int v = (int)cmd.ExecuteScalar();
if (v > 0)
{
Home home = new Home();
home.ShowDialog();
}
else
{
MessageBox.Show("Erro ao logar");
}
}
catch(MySqlException erro)
{
MessageBox.Show(erro+"No banco");
}
}
private void btentra_Click(object sender, EventArgs e)
{
logar();
}
private void btapaga_Click(object sender, EventArgs e)
{
//Limpar registros nos textbox de usuario e senha
txtusuario.Clear();
txtsenha.Clear();
}
private void btsair_Click(object sender, EventArgs e)
{
//Encerra aplicação
Application.Exit();
}