|
-
March 15th, 2010, 02:05 PM
#1
How to insert a decimal value to database?
Hi all,
I have a problem with SQL:
I have this SQL command: "insert into stores Value (Int,"String","Sting", double)
The problem is that the double has a ',' in it so the SQL think it is 5 valus and not 4.
I can not make a convert to Sting because I need to make a selection ordered by the double valu later on (that is select Ä from stores order by income (that is the double value)
Any Ideas?
-
March 15th, 2010, 02:21 PM
#2
Re: How to insert a decimal value to database?
Ahh Solved it myself Change the ',' to a '.' solves the problem
-
March 16th, 2010, 04:14 AM
#3
Re: How to insert a decimal value to database?
This depends on the culture of the server where your database runs. I think in your case, the server is set to US (where '.' is the decimal seperator), and your client pc is set to some language where ',' is the decimal seperator.
What happens when your server changes to another language. Replacing the ',' by '.' will not work anymore!!
You should use the parameters of the command
Code:
int someInt = 1;
string string1 = "test";
string string2 = "value";
double someDouble = 2.5;
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
command.CommandText = "INSERT INTO stores VALUES (@int, @string1, @string2, @double)";
command.Parameters.Add(new System.Data.SqlClient.SqlParameter() { ParameterName = "@int", Value = someInt });
command.Parameters.Add(new System.Data.SqlClient.SqlParameter() { ParameterName = "@string1", Value = string1 });
command.Parameters.Add(new System.Data.SqlClient.SqlParameter() { ParameterName = "@string2", Value = string2 });
command.Parameters.Add(new System.Data.SqlClient.SqlParameter() { ParameterName = "@double", Value = someDouble });
For the int and string values, it does not matter that much. It does for the double. Also you will have the same problems with DateTime values.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|