Insert NULL into a Money field in SQL Server

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

Who is Participating?
Anthony PerkinsCommented:
Change this:
cmdSelect.Parameters.AddWithValue("@necklacePrice", DBNull.Value)

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

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

Anthony PerkinsCommented:
But you may find experts more responsive in a more appropriate Topic Area such as:
Aneesh RetnakaranDatabase AdministratorCommented:
can you run the sql profiler and then your application to catch what exactly is coming to sql server from your application
Anthony PerkinsCommented:
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.
have you tried passing Nullif(0.00,0.00)  when you want a null?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.