2
When I run a project in Visual Studio it shows the following error:
A first chance Exception of type 'System.Data.Sqlclient.Sqlexception' occurred in System.Data.dll
Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Logar
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string conexao = "Data Source=(local);Initial Catalog=Cadastro;User ID=sa;Password=m4st3r!";
SqlConnection add = new SqlConnection(conexao);
SqlCommand comado = new SqlCommand("select count (*) Usuario where Usuario =@user and Senha=@senha", add);
comado.Parameters.Add("@user", SqlDbType.VarChar).Value = textBox1.Text;
comado.Parameters.Add("@senha", SqlDbType.VarChar).Value = textBox2.Text;
add.Open();
int i = (int) comado.ExecuteScalar();
if (i > 0)
{
MessageBox.Show("Login e senha encontrado");
}
else
{
MessageBox.Show("Erro");
}
add.Close();
}
}
}
What mistake is this?
Have you tried to continue running to see if something else happens? This usually happens as a warning that something is wrong but can still run.
– Maniero
Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?
– Maniero