Error while executing project in Visual Studio

0

When I run a project in Visual Studio it has 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 error is this?

    
asked by anonymous 25.03.2015 / 20:32

2 answers

1

This message is showing that there was an exception but it was handled by the component you are using. Most of the time you do not have to do anything and this will not happen when you're not debugging the application. It's just a warning and you can continue running smoothly.

You can disable this in Visual Studio. Some ways to do this:

  • Right-clicking on Output Window uncheck Exception Messages . ( Font )
  • There is a setting in the Debug > Exceptions menu. Open Common Language Runtime Exceptions , then System , and clear user-handled of exceptions you do not want to be shown. ( Font )

Blog that best explains how this type of message works.

    
25.03.2015 / 20:46
0

The unconventional error message is probably caused by the problem pointed to by @bigown, but there is a problem with your query:

select count (*) Usuario where Usuario =@user and Senha=@senha

Missing clause from

select count (*) from Usuario where Usuario =@user and Senha=@senha
    
25.03.2015 / 20:56