Insert NULL into a Money field in SQL Server

Posted on 2006-04-10
Last Modified: 2008-02-01
I have a form for users to enter information. If they do not enter anything into txtPrice I want it to insert NULL into the column. The column is a money column. Everytime I try this is the error I get. Implicit conversion from data type nvarchar to money is not allowed. Use the CONVERT function to run this query. Here is the code I am using to insert the data entered into the text box.

If txtNPrice.Text = "" Then
                    cmdSelect.Parameters.AddWithValue("@necklacePrice", DBNull.Value)
                    cmdSelect.Parameters.AddWithValue("@necklacePrice", Val(txtNPrice.Text))
                End If

This is an ASP.NEt application written in

Question by:ryapos
    LVL 75

    Accepted Solution

    Change this:
    cmdSelect.Parameters.AddWithValue("@necklacePrice", DBNull.Value)

    To this:
    cmdSelect.Parameters.AddWithValue("@necklacePrice", Nothing)

    Or just simply:
    cmdSelect.Parameters.Add("@necklacePrice", SqlDbType.Money)

    LVL 75

    Expert Comment

    by:Anthony Perkins
    But you may find experts more responsive in a more appropriate Topic Area such as:
    LVL 75

    Expert Comment

    by:Aneesh Retnakaran
    can you run the sql profiler and then your application to catch what exactly is coming to sql server from your application
    LVL 75

    Expert Comment

    by:Anthony Perkins
    I will go out on a limb and suggest that it is never going to get beyond ADO.NET when using DBNull.Value. In other words, it will not even get close to SQL Server, let alone SQL Profiler.
    LVL 50

    Expert Comment

    have you tried passing Nullif(0.00,0.00)  when you want a null?

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This is my first ever Article on EE or elsewhere; therefore, please bear with me if I have some discrepancies in my writing. I read many articles and questions related to "how to pass values to SSIS packages at run-time?"  Hence, this common ques…
    Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
    Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
    Via a live example, show how to shrink a transaction log file down to a reasonable size.

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now