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)
                Else
                    cmdSelect.Parameters.AddWithValue("@necklacePrice", Val(txtNPrice.Text))
                End If

This is an ASP.NEt application written in vb.net.

Thanks
ryaposAsked:
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)

0
 
Anthony PerkinsCommented:
But you may find experts more responsive in a more appropriate Topic Area such as:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/
0
 
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
0
 
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.
0
 
LowfatspreadCommented:
have you tried passing Nullif(0.00,0.00)  when you want a null?
0
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.