Results 1 to 2 of 2

Thread: ADO and Null values

  1. #1
    Guest

    Red face

    I'm hoping someone can help out out on this. I am trying to populate an ADODB.Parameter collection to submit values from a VB form to a SQL server database. (The parameter collection corresponds to the parameters of a stored procedure.)

    Here's my problem ... some of the fields can (and will) be left empty. I would like to have the database populate these fields with a NULL value. I am trying to populate the parameter collection as follows:

    Dim sMileage as string
    Dim prmMileage as ADODB.Parameter

    Let sMileage = txtMileage.text

    Set prmMileage = New ADODB.Parameter

    With prmMileage
    .Type = adDecimal
    .Size = 9
    .Direction = adParamInput
    If sMileage = "" Then
    .Value = Null
    Else
    .Value = CDec(sMileage)
    End If
    End With

    When I do it this way, I get a message about an improperly formed Parameter object. The only way I have gotten around this in the past was to pass a dummy value ("null") to the stored procedure and have it take care to change that value from "null" to NULL. In the case I have identified here, I would have to pass something like "9999.9999" since I am sending a decimal value to the database.

    Any suggestions on how I should handle a case like this? I also am passing Dates to the database, so I may have to handle that situation as well.

    Any help would be GREATLY appreciated!!!!

    Thanks in advance ...

    Dan

  2. #2
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    try:

    With prmMileage
    .Attributes = adParamNullable
    .Type = adDecimal
    .Size = 9
    .Direction = adParamInput
    If sMileage = "" Then
    .Value = Null
    Else
    .Value = CDec(sMileage)
    End If
    End With

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