nullable sqlparameter

Discussion in 'Microsoft ADO .NET' started by buran, Jul 17, 2003.

  1. buran

    buran Guest

    Dear ASP.NET Programmers,

    How can I make an sqlparamater accept NULL value programmatically? I use the
    following the code, but it does not work:

    Dim admDate As SqlParameter
    admDate = New SqlParameter("@admissionDate", SqlDbType.SmallDateTime)
    admDate.isNullable = True
    admDate.Value = CType(admissionDate, Date).Date.ToString("dd.MM.yyyy")

    The compliler throws an exception when passing System.DBNull value to the
    sqlparamater admDate.
    Thanks in advance,

    Buran
     
    buran, Jul 17, 2003
    #1
    1. Advertisements

  2. buran

    Frans Bouma Guest

    "buran" <> wrote in
    news::

    > Dear ASP.NET Programmers,
    >
    > How can I make an sqlparamater accept NULL value programmatically? I use
    > the following the code, but it does not work:
    >
    > Dim admDate As SqlParameter
    > admDate = New SqlParameter("@admissionDate", SqlDbType.SmallDateTime)
    > admDate.isNullable = True
    > admDate.Value = CType(admissionDate, Date).Date.ToString("dd.MM.yyyy")
    >
    > The compliler throws an exception when passing System.DBNull value to
    > the sqlparamater admDate.


    if you do:
    amdDate.Value = System.DBNull.Value

    this throws an exception? Which one?

    You can also pass: nothing, or simply do not pass a value, it will be NULL
    automatically. (if my memory doesn't fool me :))

    FB

    --
    Solutions Design : http://www.sd.nl
    My open source .NET Software : http://www.sd.nl/software
    My .NET Blog : http://weblogs.asp.net/FBouma
    -------------------------------------------------------------------------
     
    Frans Bouma, Jul 17, 2003
    #2
    1. Advertisements

  3. buran

    buran Guest

    Thanks, that worked :)

    "Frans Bouma" <> wrote in message
    news:Xns93BB6BA5472CDperseusnewsxs4allnl@207.46.248.16...
    > "buran" <> wrote in
    > news::
    >
    > > Dear ASP.NET Programmers,
    > >
    > > How can I make an sqlparamater accept NULL value programmatically? I use
    > > the following the code, but it does not work:
    > >
    > > Dim admDate As SqlParameter
    > > admDate = New SqlParameter("@admissionDate", SqlDbType.SmallDateTime)
    > > admDate.isNullable = True
    > > admDate.Value = CType(admissionDate, Date).Date.ToString("dd.MM.yyyy")
    > >
    > > The compliler throws an exception when passing System.DBNull value to
    > > the sqlparamater admDate.

    >
    > if you do:
    > amdDate.Value = System.DBNull.Value
    >
    > this throws an exception? Which one?
    >
    > You can also pass: nothing, or simply do not pass a value, it will be NULL
    > automatically. (if my memory doesn't fool me :))
    >
    > FB
    >
    > --
    > Solutions Design : http://www.sd.nl
    > My open source .NET Software : http://www.sd.nl/software
    > My .NET Blog : http://weblogs.asp.net/FBouma
    > -------------------------------------------------------------------------
     
    buran, Jul 17, 2003
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bob6
    Replies:
    2
    Views:
    689
    Bob Bob
    Sep 16, 2003
  2. EricZa

    Auto-Created SqlParameter Definitions

    EricZa, Oct 29, 2003, in forum: Microsoft ADO .NET
    Replies:
    0
    Views:
    288
    EricZa
    Oct 29, 2003
  3. Niksa Baldun

    Problem with passing SqlParameter in VB.NET

    Niksa Baldun, Dec 8, 2003, in forum: Microsoft ADO .NET
    Replies:
    3
    Views:
    5,464
    Niksa Baldun
    Dec 9, 2003
  4. Jim Heavey

    SQLParameter - What is the difference?

    Jim Heavey, Dec 10, 2003, in forum: Microsoft ADO .NET
    Replies:
    4
    Views:
    523
    William \(Bill\) Vaughn
    Dec 11, 2003
  5. Michael

    SqlParameter SqlDBType.text size

    Michael, Jan 6, 2004, in forum: Microsoft ADO .NET
    Replies:
    1
    Views:
    4,785
    Miha Markic
    Jan 7, 2004
Loading...

Share This Page