I want select multiple (all) values from table Account.
string query = "SELECT * FROM Account";
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand(query, connection);
SqlDataReader reader;
connection.Open();
reader = command.ExecuteReader();
reader.Read();
label1.Text = reader["PasswordHash"].ToString();
connection.Close();
Why is this always returning only the first row. Actually it return one row, because if I set in where clause something like where id = 2 and id = 3 it still returns only one value.
Table have more than one value i checked form Management Studio, there query run as they should.
Thanks in advance.
Because you are not looping through the query results, it shows up only one result.
The above code loops through the query results and will give you what you want in a concatenated string assigned to
label1.text. You can also view the results by insertingConsole.WriteLine(reader["PasswordHash"].ToString());in thewhileloop