String query = "SELECT TOP 1 * FROM Accs WHERE email = '" + richTextBox1.Text + "' AND password = '" + richTextBox2.Text + "'";
SqlDataAdapter sda = new SqlDataAdapter(query, conn);
DataTable dtable = new DataTable();
sda.Fill(dtable);
if (dtable.Rows.Count > 0)
{
// the login operation is successful
email = richTextBox1.Text;
pass = richTextBox2.Text;
}
You can select only 1 row by adding TOP 1
in the start of the query to get only 1 result and yes if you want the username you can get it from
if (dtable.Rows.Count > 0)
{
// the login operation is successful
email = rickTextBox1.Text;
pass = rickTextBox1.Text;
username = dtable.Rows[0]["username"];
}
Since the image you provided shows that the username column in your database is the first one so you can do it like this as well inside your for loop
username = dtable.Rows[0][0];
or you can change your query to like this to get only the username
String query = "SELECT TOP 1 username FROM Accs WHERE email = '" + richTextBox1.Text + "' AND password = '" + richTextBox2.Text + "'";
Instead of getting all the columns you can query for the require column by replacing * in the select command with the column or columns that you are needed for example if you want username and password you can pass this query as well
String query = "SELECT TOP 1 username,email FROM Accs WHERE email = '" + richTextBox1.Text + "' AND password = '" + richTextBox2.Text + "'";
in the last query you will get 2 columns if the passing arguments are correct and database has record against that entry