473,396 Members | 1,676 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,396 software developers and data experts.

CONVERT c# decimal to SQL ???

I have a decimal amount in c#:

decimal amounT = 62.75;

and I need INSERT it into a SQL record as a money value.

string strSQL2 = "INSERT INTO trvlDetail(amountfield) ""VALUES ('" +
amounT + "') ";

Should I use a CONVERT in SQL (if so, how?) or what would be the
equivelent in c#?
Thanks,
Trint

Nov 17 '05 #1
10 21130
Hi Trint,

Use an SqlParameter, it will convert for you
decimal amounT = 62.75;

SqlParameter param = new SqlParameter(@amounT, amounT);

string strSQL2 = "INSERT INTO trvlDetail(amountfield) VALUES (@amounT)";

SqlCommand insertCommand = new SqlCommand(strSQL2, SqlConnection1);

insertCommand.Parameters.Add(param);

SqlConnection1.Open();
insertCommand.ExecuteNonQuery();
SqlConnection1.Close();
On Wed, 20 Apr 2005 14:22:49 +0200, trint <tr***********@gmail.com> wrote:
decimal amounT = 62.75;


--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #2
Hi Trint,

Use an SqlParameter, it will convert for you
decimal amounT = 62.75;

SqlParameter param = new SqlParameter(@amounT, amounT);

string strSQL2 = "INSERT INTO trvlDetail(amountfield) VALUES (@amounT)";

SqlCommand insertCommand = new SqlCommand(strSQL2, SqlConnection1);

insertCommand.Parameters.Add(param);

SqlConnection1.Open();
insertCommand.ExecuteNonQuery();
SqlConnection1.Close();
On Wed, 20 Apr 2005 14:22:49 +0200, trint <tr***********@gmail.com> wrote:
decimal amounT = 62.75;


--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #3
Thanks!

..Net programmer
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #4
Thanks!

..Net programmer
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #5
Ok, I did as you said and got this error:

"Disallowed implicit conversion from data type varchar to data type
money, table 'tsNess.dbo.trvlDetail', column 'amount'. Use the CONVERT
function to run this query."

..Net programmer
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #6
Ok, I did as you said and got this error:

"Disallowed implicit conversion from data type varchar to data type
money, table 'tsNess.dbo.trvlDetail', column 'amount'. Use the CONVERT
function to run this query."

..Net programmer
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #7
Did you remove the ''?

VALUE(@amounT) without ''
On Wed, 20 Apr 2005 15:44:20 +0200, Trint Smith <tr***********@gmail.com> wrote:
Ok, I did as you said and got this error:

"Disallowed implicit conversion from data type varchar to data type
money, table 'tsNess.dbo.trvlDetail', column 'amount'. Use the CONVERT
function to run this query."

.Net programmer
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***


--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #8
Did you remove the ''?

VALUE(@amounT) without ''
On Wed, 20 Apr 2005 15:44:20 +0200, Trint Smith <tr***********@gmail.com> wrote:
Ok, I did as you said and got this error:

"Disallowed implicit conversion from data type varchar to data type
money, table 'tsNess.dbo.trvlDetail', column 'amount'. Use the CONVERT
function to run this query."

.Net programmer
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***


--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #9
Sorry, forgot to remove that. It works now.

Morten Wennevik wrote:
Did you remove the ''?

VALUE(@amounT) without ''
On Wed, 20 Apr 2005 15:44:20 +0200, Trint Smith <tr***********@gmail.com> wrote:
Ok, I did as you said and got this error:

"Disallowed implicit conversion from data type varchar to data type
money, table 'tsNess.dbo.trvlDetail', column 'amount'. Use the CONVERT function to run this query."

.Net programmer
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***


--
Happy coding!
Morten Wennevik [C# MVP]


Nov 17 '05 #10
Sorry, forgot to remove that. It works now.

Morten Wennevik wrote:
Did you remove the ''?

VALUE(@amounT) without ''
On Wed, 20 Apr 2005 15:44:20 +0200, Trint Smith <tr***********@gmail.com> wrote:
Ok, I did as you said and got this error:

"Disallowed implicit conversion from data type varchar to data type
money, table 'tsNess.dbo.trvlDetail', column 'amount'. Use the CONVERT function to run this query."

.Net programmer
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***


--
Happy coding!
Morten Wennevik [C# MVP]


Nov 17 '05 #11

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

Similar topics

13
by: Jason | last post by:
Could someone here show me how I would write a vb program to convert decimal ip address to binary? For example a small form with a convert button and a label for the result and a textbox for the...
5
by: Ray | last post by:
I have a table with some audit date and time columns. Problem is the developer who stored the data left them as DECIMAL type instead of DATE and TIME. Is there a way I can convert the DECIMAL type...
13
by: muss | last post by:
how to convert decimal number in a hexadecimal number using C? Please help me. Thanks.
5
by: lathasree | last post by:
Hi, this is sreelatha give a c progrm to convert decimal to binary.... thank u....
6
by: sweeet_addiction16 | last post by:
hello Im writin a code in c... can sum1 pls help me out in writing a c code to convert decimalnumber to hexadecimal number.The hexadecimal number generated has to be an unsigned long.
1
by: karanbikash | last post by:
Hi , I have a requirement where in I need to display the decimal value of 0.00 as '######.00' SELECT case when DECIMAL(AMT_CHEQUE,31,2) = 0.00 THEN 9999999999999.9999999 ELSE ...
2
nirmalsingh
by: nirmalsingh | last post by:
Hai all, i want to convert decimal to time. for example if i have decimal number 09.6 then i need it as 10.00 and also decimal 10.118 as 11.58. How to convert this? Thanx in advance with Cheers...
1
by: Vitaliy | last post by:
Hi I got this wired exception periodically (Python 2.5, Django based application) what does it mean ?
4
by: Rolandas | last post by:
Hi, Can anyone help me? I need a code in VBA which would convert decimal numbers to the other system bases on number 36. e.g. in this page...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
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...

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.