Results 1 to 4 of 4

Thread: [RESOLVED] searching a database for enteries with blank dates

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    255

    Resolved [RESOLVED] searching a database for enteries with blank dates

    hello

    i need to populate my datagrid view with records from my database.
    the records i require are the ones that have not yet been closed so i wish to search for all records where there is no date in the closed column.

    im not sure how to write my sql, i tried.....
    select * from table where closed = ""

    i just get a syntax error

    i looked on the net but couldnt find any examples of searching by a blank date!

    Thanks,

    Iain

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: searching a database for enteries with blank dates

    "Blank" values are commonly said to be NULL:
    Code:
    SELECT * FROM MyTable WHERE MyColumn IS NULL
    Note that this is actually an SQL question and belongs in the Database Development forum. It has no specific connection to VB.NET.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    255

    Re: searching a database for enteries with blank dates

    ah brilliant!!
    thanks alot!
    i tried db.null and got no where with that, didnt even occur to me to just use null!
    cheers!

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] searching a database for enteries with blank dates

    DBNull is a .NET type. It's nothing to do with SQL. If you assign DBNull.Value to a parameter or field in VB code then that becomes NULL when inserted into the SQL, e.g.
    vb.net Code:
    1. Dim command As New SqlCommand("SELECT * FROM MyTable WHERE MyColumn IS @MyColumn", connection)
    2.  
    3. command.Parameter.Add("@MyColumn", SqlDbType.VarChar, 50).Value = DBNull.Value
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width