I am using SqlReader object(reader) to assign a string value from Sql-server database to an image's ImageUrl, but the ImageUrl is always empty while the reader object doesn't satisfy the while loop condition when debugging.
protected void Button3_Click(object sender, EventArgs e)
{
string query = "select profilePicture from Users where username = '@username'";
command = new SqlCommand(query, connection);
command.Connection = connection;
command.Parameters.Add("@username", SqlDbType.VarChar).Value = User.Identity.Name;
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
ProfilePhotoButton.ImageUrl = reader[0].ToString();
}
}
connection.Close();
}