Code problem probably coming from Sqlserver

Asked

Viewed 31 times

-1

I’m trying to create a very simple login system, I’m new to programming and I’m still learning and I came across a mistake, The compiler does not present any errors however when running and trying to log in even with right or even wrong data when clicking the access button it presents this error. this is my first question so if I forgot something please correct me and ask.

imagem com o codigo do erro I already modified the string in several ways but the error persists, the Sqlservver service is running correctly and at first connected to the visual studio. follow the code to see if you can help me.

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;
using System.Data.OleDb;

namespace TesteDeLogin3
{
    public partial class TelaDeLoguin1 : Form
    {
        public TelaDeLoguin1()
        {
            InitializeComponent();
        }

        private void btnsair_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnacessar_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-LHJNB75;Initial Catalog=BancoDeLogin;Integrated Security=True;Pooling=False");
            SqlDataAdapter sda = new SqlDataAdapter("Select Count(*)  *From Table where usuario=' " + txbuser.Text + "' and senha ='" + txbsenha.Text + "'", con);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            if (dt.Rows[0][0].ToString() == "1")
            {
                this.Hide();

                TelaDeEntrada ss = new TelaDeEntrada();
                ss.Show();
            }
            else
            {
                MessageBox.Show("Por favor verifique as informaçoes digitadas e tente novamente");
            }
        }

        private void TelaDeLoguin1_Load(object sender, EventArgs e)
        {
            
            this.tableTableAdapter.Fill(this.bancoDeLoginDataSet.Table);

        }

        
    }
}

  • Try taking the * that’s glued to the From. Instead of *From, will be From

  • I made the modification but the error continues

2 answers

0

Your query is incorrect:

SqlDataAdapter sda = new SqlDataAdapter("Select Count(*) *From Table where usuario=' " + txbuser.Text + "' and senha ='" + txbsenha.Text + "'", con);

The right thing would be:

SqlDataAdapter sda = new SqlDataAdapter("Select Count(*) From Table where usuario=' " + txbuser.Text + "' and senha ='" + txbsenha.Text + "'", con);

  • Thank you, but I made the correction and still present the same error still

0

As your query was answered this with an extra * I believe I could use it as follows:

var sda = new SqlDataAdapter($"SELECT COUNT(1) From Table WHERE usuario='{txbuser.Text}' and senha ='{txbsenha.Text}'", con)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.