Link to home
Create AccountLog in
Avatar of LT1415
LT1415

asked on

Checking for Null Values Database Column

I need to check for null values in a database column [13].

If it's Null then show the expand collaspe button

if it's not null then show the transparent gif.

(The column will either have the word NULL or the word Inactive if it's not null)
       


Column 13 is in pTableZero which I tried to state like this
pTableZero.Rows[i][13]


Here is the code that either shows the expand button or shows a transparent button.
 




StringBuilder sb = new StringBuilder();

        if (RowCount > 0)

        {

            for (int i = pCursor; i < pNumberOfRows; i++)

            {

                if ((pTableZero.Rows[i].GetChildRows("TableZero2TableOne").Length > 0)

||(pTableZero.Rows[i].GetChildRows("TableZero2TableThree").Length > 0)) // error line

                {

                    buttonForChildRows = "<img name=\"collapsible\" src=\"images/button_plus_2.jpg\"

onclick=\"collapseDaTable(this)\" title=\"Expand Record\" alt=\"Expand Collapse Button\"></img>";

                }

                else

                {

                    buttonForChildRows = "<img src=\"images/button_transparent.gif\" alt=\"\"></img>";

                }

thanks
ASKER CERTIFIED SOLUTION
Avatar of p_davis
p_davis

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Martman100
Martman100

You can also try replacing the == "NULL" with == System.DBNull.Value from an ADO perspective.
Avatar of LT1415

ASKER

Thank you:
p davis: I tried your suggestion a few different ways but I am getting an error

CS0019: Operator '==' cannot be applied to operands of type 'method group' and 'string'

if ((pTableZero.Rows[i].GetChildRows("TableZero2TableOne").Length > 0) || (pTableZero.Rows[i].GetChildRows("TableZero2TableThree").Length > 0) || (pTableZero.Rows[i][13].ToString == "NULL"))

Also tried it separated from these other conditions as you sent in your post but got the same error
CS0019: Operator '==' cannot be applied to operands of type 'method group' and 'string'



also tried

if ((pTableZero.Rows[i].GetChildRows("TableZero2TableOne").Length > 0) || (pTableZero.Rows[i].GetChildRows("TableZero2TableThree").Length > 0) || (pTableZero.Rows[i][13].ToString = "NULL"))
Error
CS1656: Cannot assign to 'ToString' because it is a 'method group'


if(pTableZero.Rows[i][13].ToString == NULL)
Error
CS0103: The name 'NULL' does not exist in the current context

SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
yes martman100 is correct -- sorry about the typos i was in a hurry and didn't proof read and the second should read
else if(pTableZero.Rows[i][13].ToString() =="Inactive")

but you didn't answer my question about null-- will the value actually be represented by a null or will it be a string that holds the word NULL?
Hi,
   Use IsDBNull() like below.
 
    if IsDBNull(pTableZero.Rows[i].GetChildRows("TableZero2TableThree"))
                 //show collapse button
    else
                //show transparent GIF.
Avatar of LT1415

ASKER

pdavis: Thank you.

I am wrong..The database column will never be null.
However the check is still applicable.

I need to check for  "Inactive" or "Active"
Right now, the program is not recognizing the check as stated below.

I am thinking that the column value should be set to some type of variable in order to do .ToString()
example:
x=pTableZero.Rows[i][6].ToString();

I am not sure how to answer your question about whether a string would hold the value of the column because we need the program to check the value but not display it on the screen.

This is what I am using now.
if(pTableZero.Rows[i][6].ToString() == "Active")
{
  buttonForChildRows = "<img name=\"collapsible\" src=\"images/button_plus_2.jpg\" onclick=\"collapseDaTable(this)\" title=\"Expand Record\" alt=\"Expand Collapse Button\"></img>";
}
else if(pTableZero.Rows[i][6] =="Inactive")
{  buttonForChildRows = "<img src=\"images/button_transparent.gif\" alt=\"\"></img>";

}




those if statements look correct can you set a break point and check the values of the table row/column and the indices's that you have set
p_davis's statement looks good to me too. Just a reminder the Rows and columns are on a 0 based index in case this may be the last column.