当我试图从数据库中获取位值时,它会出错。下面给出以下代码:
SqlCommand cmd = new SqlCommand("SELECT ISADMIN FROM USER_DETAILS WHERE USER_NAME=@User AND ISPASSWORD=@Pass", con);
cmd.Parameters.AddWithValue("@User", cbUserName.Text);
cmd.Parameters.AddWithValue("Pass", txtPassword.Text);
SqlDataReader dr = cmd.ExecuteReader();
b = (bool)dr["ISADMIN"];//*Here it gives error
错误:
不存在数据时尝试读取无效。