473,473 Members | 1,489 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Insert DBNull.Value into Sql Money field fails. (You've got to love it!)

Hi all,

I'm trying to get a null value into a sql money field through a
SqlCommand in c#.

However, I get this lovely message (which sparks loads of happy
emotions in this overworked body):

Disallowed implicit conversion from data type nvarchar to data type
money, table 'xxxx', column 'xxxx'. Use the CONVERT function to run
this query.

I tried inserting good ol' "null" values, without any luck.

Anyone ever came accross something like this?

Best,
Andre

Nov 17 '05 #1
4 9259
KH
Assuming the field accepts NULLs ... I believe all the Sql* types have a
..Null static field, so the parameter value would be SqlMoney.Null

Alternativly you could create the parameter as a SqlMoney type - one of the
overlopaded constructors - and not sets its value, so it should default to
NULL
"ah****@gmail.com" wrote:
Hi all,

I'm trying to get a null value into a sql money field through a
SqlCommand in c#.

However, I get this lovely message (which sparks loads of happy
emotions in this overworked body):

Disallowed implicit conversion from data type nvarchar to data type
money, table 'xxxx', column 'xxxx'. Use the CONVERT function to run
this query.

I tried inserting good ol' "null" values, without any luck.

Anyone ever came accross something like this?

Best,
Andre

Nov 17 '05 #2
Andre,

I haven't seen this since my classic ASP days when I used to use a lot
of embedded SQL. Every time this error came up, it's because I wanted
to set a value to NULL, but I was passing it as a string and this
caused a type mismatch error to occur.

Are you using embedded SQL or a stored procedure in this case? If
you're using embedded SQL, are you using parameterized SQL or just
building a string on the fly? If it's the later, please post a
"scrubbed" version of the SQL so we can have a look at the query you're
trying to execute.

Thanks,
Denny Boynton

Nov 17 '05 #3
<ah****@gmail.com> wrote:
I'm trying to get a null value into a sql money field through a
SqlCommand in c#.

However, I get this lovely message (which sparks loads of happy
emotions in this overworked body):

Disallowed implicit conversion from data type nvarchar to data type
money, table 'xxxx', column 'xxxx'. Use the CONVERT function to run
this query.

I tried inserting good ol' "null" values, without any luck.

Anyone ever came accross something like this?


Well, how are you trying to insert it at the moment? Does your
SqlCommand parameter definitely know that it's a money field?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4
Hi all,

Thanks for all the help and suggestions.

I replaced SqlMoney.Null with DBNull.Value (in the relevant
SqlParameter in the SqlCommand), which did the trick.

Many thanks,
Andre

Jon wrote:
<ah****@gmail.com> wrote:
I'm trying to get a null value into a sql money field through a
SqlCommand in c#.

However, I get this lovely message (which sparks loads of happy
emotions in this overworked body):

Disallowed implicit conversion from data type nvarchar to data type
money, table 'xxxx', column 'xxxx'. Use the CONVERT function to run
this query.

I tried inserting good ol' "null" values, without any luck.

Anyone ever came accross something like this?


Well, how are you trying to insert it at the moment? Does your
SqlCommand parameter definitely know that it's a money field?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Daniel Zelisko | last post by:
Hello Could anyone tell me how to send a null decimal value to the sql server depending on its value? The following code gives me an error: System.Data.SqlTypes.SqlNullValueException: Data is...
0
by: Boris Zakharin | last post by:
I have a table (jobs) where a field (email) is defined as varchar(50) and can be set to null. How do I do that? For example, I have an OleDbCommand called cmdSub and I perform the following: ...
6
by: FatboyCanteen | last post by:
When I using dataset to append a null value to the datetime field. It throw a error -> can not convert db.null to system.date Can there is any standard to pass a Null value to the DateTime...
1
by: Marty U. | last post by:
I have a form that has several fields that need to update a db record using SQL Data Provider. What is the best practice to insert DBNull if a text field is empty? I normally use if (txtbox.text...
3
by: NuB | last post by:
I have a grid on a winForm, where I can enter a date or leave it blank for data entry. If I have a data field blank I get a DBNull value error, how can I allow a blank date field in my grid be...
2
by: Julian | last post by:
I have the following code: Dim strQuery As String = "SELECT tblData.CoPayFundGrant, tblData.M_DSS_SSA_Benefits, tblData.O_DSS_SSA_Benefits, " & _ "tblData.Ref_MPS, tblData.Ref_LA,...
5
by: darrel | last post by:
I should know this, but I don't... How do I enter a null value in an integer field using parameterized SQL? I have this: Dim bonding2ID As Integer If...
4
by: Laurahn | last post by:
How can i send from VB 2005 a null value to a image field on a database in SQL 2005
3
by: tvnaidu | last post by:
When I do INSERT like below, value is a string with apastrophe (for ex: "Checking for 'hlt' instruction"), insert throws an error - how to fix? INSERT INTO table_name (column1, column2,...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.