473,327 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Error While inserting

Hi All,
I'm getting following error while executing insert query using
SqlCommand object with parameters
Insert Failed :Disallowed implicit conversion from data type
nvarchar to data type money

I'm adding Parameters using following syntax
SqlCommand cmd= new SqlCommand();
---
---
string myValue = "20"
cmd.Parameters.Add(new SqlParameter("@MyMoneyColName",myValue))
-----
cmd.ExecuteNonQry();

there is a Constructor of SqlParameter available
which takes SqlDbType as parameter, but the problem is that i don't
have parameter info, coz i'm writing these qry at run time.
Can some one please help me on this
Thanks
SunilT

Jul 12 '06 #1
3 912
Sunil,

Don't declare myval as a string.

decimal myval = 20;

Regards,

--
S. Justin Gengo
Web Developer / Programmer

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
<su******@gmail.comwrote in message
news:11*********************@35g2000cwc.googlegrou ps.com...
Hi All,
I'm getting following error while executing insert query using
SqlCommand object with parameters
Insert Failed :Disallowed implicit conversion from data type
nvarchar to data type money

I'm adding Parameters using following syntax
SqlCommand cmd= new SqlCommand();
---
---
string myValue = "20"
cmd.Parameters.Add(new SqlParameter("@MyMoneyColName",myValue))
-----
cmd.ExecuteNonQry();

there is a Constructor of SqlParameter available
which takes SqlDbType as parameter, but the problem is that i don't
have parameter info, coz i'm writing these qry at run time.
Can some one please help me on this
Thanks
SunilT

Jul 12 '06 #2

Hi Justin,
you said "Don't declare myval as a string , use decimal myval = 20;"
but the problem is that i don't know the datatype of the parameter
being added to SQLParameters collection it could be money,varchar,date
etc.

Thanks
SunilT

Jul 17 '06 #3
Sunil,

In that case cast the the variable to a decimal as it's added.

cmd.Parameters.Add("@MyMoneyColName", SqlDbType.Money).Value = (decimal)
myValue;

Regards,
--
S. Justin Gengo
Web Developer / Programmer

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
<su******@gmail.comwrote in message
news:11**********************@s13g2000cwa.googlegr oups.com...
>
Hi Justin,
you said "Don't declare myval as a string , use decimal myval = 20;"
but the problem is that i don't know the datatype of the parameter
being added to SQLParameters collection it could be money,varchar,date
etc.

Thanks
SunilT

Jul 17 '06 #4

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

Similar topics

2
by: Charles Wilt | last post by:
I have a IBM iSeries (aka AS-400) running v5r3 of OS/400 that I access via a linked server from SQL Server 2000. The following select works fine: select * from...
1
by: ing42 | last post by:
I have a problem with inserting records into table when an indexed view is based on it. Table has text field (without it there is no problem, but I need it). Here is a sample code: USE test GO...
10
by: Phil Latio | last post by:
I am inserting data into user table which contains 5 fields, sounds simple enough normally but 2 of the fields are designated as UNIQUE. If someone does enter a value which already exists, how do I...
1
by: madhuxml82 | last post by:
Dear Forum Members, I have generated an XML Schema and a Table of XMLType referencing the XML Schema. Now When I am Inserting the Data into the Table. I am getting the Error 0RA-30937: Error is...
0
by: mbenedict | last post by:
I am rather new at this code and am attempting to modify existing code to use clob datatypes, which I have never used before. The database tables have been set up for clob data. When trying to use...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.