473,325 Members | 2,872 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,325 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 21121
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.