How to Select Field from a Table in Microsoft SQL Server Management Studio (SSMS) through C#?

Asked

Viewed 19 times

-1

I am making a login system, and for the login to be valid, I must read the value entered in txtNome (where the user will have entered the name he registered), save the text in a variable and perform a select in the field usuario database to check if the name entered by the user is correct. However I am not able to perform the select.

        nome = txtNomeMail.Text;
        try
        {
        con = getConexaobd();
        con.Open();
        SqlCommand cmd = new SqlCommand("select usuario from dados where usuario = @nomeusuario");
        cmd.Connection = con;
        SqlParameter teste = new SqlParameter();
        teste.ParameterName = "@nomeusuario";
        teste.Value = nome;
        cmd.Parameters.Add(teste);
        rdr = cmd.ExecuteReader();
        txtSelog.Text = rdr.ToString();
        }

        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

The response of txtSelog is the structure of the command and not the result of it. I would like to know how to perform the select the correct way and how to compare what the select bring back what the user typed in txtNomeMail

Note: Connection is opening normally.

Obs2: txtSelog is a TextBox that I put on to display the result of select to see if it’s working.

  • Please clarify your problem or provide additional details in order to highlight exactly what you need. The way it’s written these days it’s hard to tell exactly what you’re asking.

  • https://docs.microsoft.com/pt-br/dotnet/api/system.data.idatareader?view=net-5.0

No answers

Browser other questions tagged

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