Data reader and NULL values
Posted on 2011-02-26
I am using data reader for reading data from the table. For this particular case no record was found and I am getting the following error. InvalidOperationException was unhandled by user code
Invalid attempt to read when no data is present.
In reality I am looking for both values then I have data and when there is none. How can I handle this problem that it would not throw an exception? Thanks!
protected void CustomerLevel()
SqlConnection Conn = new SqlConnection(ConnString);
SQL = "Select level from CustomerTable where Name = '" + CustName + "'";
SqlCommand cmd = new SqlCommand(SQL, objConn);
r = cmd.ExecuteReader();
if (!(r["level"] == DBNull.Value))
Custlevel = r["level"].ToString();
Custlevel = "";
level = Custleve;
HttpCookie Cookie1 = new HttpCookie("level", level);