-1
When trying to perform a query to a local database in Visual Studio, returns an exception.
Code I am using in FORM1, LOGIN button.
string sql = "(SELECT * FROM Login WHERE CNPJ ='"+textBox1.Text+"'AND senhaCorp ='"+textBox2.Text+"')";
SqlConnection con = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\Users\ThiagoSantana\source\repos\ArqX\ArqX\DBPaciente.mdf; Integrated Security = TrueconnectionString");
SqlCommand cmd = new SqlCommand(sql, con);
cmd.CommandType = CommandType.Text;
SqlDataReader reader;
con.Open();
reader = cmd.ExecuteReader();
try
{
if (!reader.Read())
{
MessageBox.Show("Login e senha incorreta");
}
else
{
this.Hide();
ViewPrincipal vp = new ViewPrincipal();
vp.Show();
}
}
catch (Exception ex)
{
MessageBox.Show("Erro: " + ex.ToString());
}
finally
{
con.Close();
}
Don’t forget to vote and accept the answer if it has solved your problem.
– tvdias
Add the exception details to the question, please.
– tvdias
You managed to solve your problem?
– tvdias