Putting NULL from MySql into a SPListItem ? RRS feed

  • Question

  • I am getting information from a MySQL table and putting it into a SPList. This all works fine. But when I run the script again and retreive the data out of the SPList, the code does not like the NULL values. If I run an IF Statement that includes one of the SPListItems which has a value of NULL, the script throws an exception. If I try to run string.IsNullOrEmpty(myListItem["Title"]) , the script throws an exception.

    try {
        if (myListItem["Title"] == "ABC") {
            // do something
        } else {
          // do something else
    } catch {
        // lands in here if myListItem["Title"] = NULL
    Can someone tell me, is the SPListItem not actually giving me NULL? Is it giving me anything? The Object doesn't seem to be initialized, but it can then go to the SPListItem and get the data from that same column.
    Friday, October 2, 2009 8:34 PM


  • Just explicitly do a ToString(), like myListItem["Title"] .ToString() before checking it for isnullorempty. This should not give you the exception that you are saying
    Sundar Narasiman
    • Marked as answer by Chengyi Wu Wednesday, October 14, 2009 1:27 AM
    Friday, October 2, 2009 9:51 PM