Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a sql UPDATE command that i have some trouble with. In my database i have 3 similar(have the same specs) columns these columns contain a line of numbers which is 81 char always 81 char long. I have a normal INSERT INTO command which works fine. but when i use the UPDATE command to update these. I get a problem where after the first number it puts a comma:
Example(normal:987987987, with problematic code:9,8798797) how can i do it without the comma?
Here is the code:
ki1/2/3 are strings that contain the line of numbers.

C#
OleDbConnection con1 = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=userstat.accdb;Persist Security Info=false;");
                con1.Open();
                OleDbCommand cmd1 = new OleDbCommand("UPDATE save SET mapfull="+ki1+",mapinitial="+ki2+",mapcurrent="+ki3+";", con1);
                cmd1.ExecuteNonQuery();
                con1.Close();
Posted
Comments
Sascha Lefèvre 3-Apr-15 9:14am    
Do I understand correctly, ki1/2/3 actually (can) contain a comma? Or where does the comma come from? And if the comma is in ki1/2/3, is that alright up to the update statement or wouldn't it be maybe best to avoid it in the first place?
Member 11338785 3-Apr-15 9:37am    
They 'can' contain a comma but they don't somehow they get added during the UPDATE line and i dont know why.
Maciej Los 3-Apr-15 9:45am    
Please, provide more details: a structure of table, sample data, expected output.
Member 11338785 3-Apr-15 10:24am    
Sample data is there and so is the expected result.

1 solution

As ki1/ki2/ki3 are strings you would have to quote them. I assume you did that in your insert-statement and just forgot that here.

But: You shouldn't build your query-strings by concatenating the values as literals anyway.

Instead you should use SQL-Parameters. Please see one of my previous answers where I wrote an exemplary "good practice" database-access (a select-statement there but that doesn't matter). I also explain there the advantages of SQL-Parameters:

how to loop sql server table to create a datagridview - sql table field matches csv field[^]


Edit: The code-formatting is a bit messed up there, unfortunately, because of slight bugs with this website. There's a <pre>-Tag in the code that doesn't belong there and the last line isn't part of the code-block any more.
 
Share this answer
 
v3
Comments
Member 11338785 3-Apr-15 10:29am    
Yeah i 'forgot' to quote them :).Thanks for your answer!
Sascha Lefèvre 3-Apr-15 10:34am    
You're welcome!
But please take a look at my suggestion regarding SQL-Parameters. You will spare yourself trouble in the future when using them :-)
Member 11338785 3-Apr-15 11:01am    
Oh believe me i did! I have it in a txt on my pendrive :D.
Sascha Lefèvre 3-Apr-15 11:05am    
Very good ;-)
Maciej Los 4-Apr-15 13:40pm    
+5, Sascha!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900