PankaJ D

PankaJ D

  • NA
  • 154
  • 0

How to checkNull values using Execute Scalar

Feb 17 2011 12:26 AM

string strmcat = "select idcategory from categories where categorydesc='" + mcategory + "'";
        SqlCommand com = new SqlCommand(strmcat, conn);
        conn.Open();
       
         Object o = (Object)com.ExecuteScalar();
        if ( o != DBNull.Value)
        {
            idmcat = (int)com.ExecuteScalar();
        }
        conn.Close();
What wrong with this code.When null values return from db then also control goes in if condition.

Answers (3)