我正在尝试检查用户是否已经在数据库中,但它始终在sqlConnection.Close()
末尾通过,因此该按钮没有执行任何操作。
这就是我想要做的:
private void RegisterButton_Click(object sender, RoutedEventArgs e)
{
string Username = txtUsername.Text;
//condition
//condition
sqlConnection.Open();
string query = "select * from Users where Username = @Username";
sqlCommand.sqlCommand = new SqlCommand(query, sqlConnection);
sqlCommand.Parameters.AddWithValue("@Username", Username);
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
if(!sqlDataReader.HasRows)
{
while(sqlDataReader.Read())
{
Users users = new Users(); //this is my object
users.IdUser = Convert.ToInt32(sqlDataReader["IdUser"]);
users.Username = sqlDataReader["Username"].ToString();
users.Password = Convert.ToChar(sqlDataReader["Password"]);
users.ConfirmPassword = Convert.ToChar(sqlDataReader["ConfirmPassword"]);
// there's more but I won't paste it. the problem is at the object..
}
}
}
没有错误消息,但是什么也没有发生。 。