Link to home
Start Free TrialLog in
Avatar of ryapos
ryaposFlag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
But you may find experts more responsive in a more appropriate Topic Area such as:
https://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/
can you run the sql profiler and then your application to catch what exactly is coming to sql server from your application
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?