Insert NULL into a Money field in SQL Server

Posted on 2006-04-10
Medium Priority
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 vb.net.

Question by:ryapos
  • 3
LVL 75

Accepted Solution

Anthony Perkins earned 2000 total points
ID: 16423045
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
ID: 16423047
But you may find experts more responsive in a more appropriate Topic Area such as:
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 16423049
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
ID: 16423071
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

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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

850 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