我想从数据库中获取所有行,以便可以与用户在文本框中输入的值进行比较。但是数据读取器正在为第一行提供数据库。
SqlCommand sqlCommand = new SqlCommand("Select * from
POSbyahmar.dbo.Accounts where Name = '" + UserName.Text + "' ",
sqlConnection);
SqlDataReader dataReader;
dataReader = sqlCommand.ExecuteReader();
while(dataReader.Read())
{
string usernamefrmdatabase =
dataReader["Name"].ToString();
string passwordfromdatabase =
dataReader["Password"].ToString();
string uusernamefromuser = UserName.Text;
string passwordfromuser = PasswordTextBox.Text;
if (String.Equals(usernamefrmdatabase,
uusernamefromuser))
{
MessageBox.Show("reader working");
MessageBox.Show(usernamefrmdatabase);
MessageBox.Show(passwordfromdatabase);
}
//MessageBox.Show(usernamefrmdatabase);
// MessageBox.Show(passwordfromdatabase);
}