Click here to Skip to main content
15,040,003 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I want to UPdate unicode Data in my table.
i used following Query for insert unicode ...

string query = "INSERT AddDoze values (N' " + txt_doze.Text + "')";
and thats work properly ...

But i am facing problem in updating Data. I used following Query for updating unicode

string Query = "update dbo.AddDoze set Meddoze= '" + DozeName + "' where ID= '" + ID + "' ";

when i m updating data ... its stored in Database table like a Question marks ???????

So please any one tell me there is any solution(Query) to updating Unicode Data in C# .net?
Updated 3-Jul-12 9:26am
Wrong way of building queries anyway -- very unsafe, an easy target for SQL injection. You need to use parametrized queries.

First off, do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

You may find that improves things, but if it doesn't then you may need to convert the data from Unicode to ASCII instead - although SQL supports Unicode perfectly happily when prefixed by 'N' as in your original code.
So add the prefix to your second code example, and it should work there as well!
miss_sumaira 3-Jul-12 15:54pm
i used N' as a prefixed. but its not working .... and gives Incorrect Format Exception.
If ID is Interger type then dont use ' with ID. Use Below SQL-

string Query = "update dbo.AddDoze set Meddoze = '" + DozeName + "' where ID = " + ID +"";
miss_sumaira 3-Jul-12 15:56pm
yeah i use this one also. but Does not affect..
divesh12 3-Jul-12 16:55pm
Please Post your Code.
miss_sumaira 3-Jul-12 17:09pm
GridViewRow row = (GridViewRow)gvw.Rows[e.RowIndex];
Int32 ID = Int32.Parse(gvw.DataKeys[e.RowIndex].Value.ToString());
string investgation = ((TextBox)(row.Cells[1].Controls[0])).Text;

string Query = "update dbo.Investigations set Investigations= '" + investgation + "' where ID= " + ID + " ";
gvw.EditIndex = -1;

catch (Exception ex)
string strEx = ex.Message;

divesh12 3-Jul-12 17:48pm
Use this Query-
string Query = "update dbo.AddDoze set Meddoze= N'" + DozeName + "' where ID= " + ID + "";
miss_sumaira 4-Jul-12 8:16am
after added this Query, my Data-updated Successfully but its not Accepting NEW Value in grid view its again used previous value...

Like if database Table stored that value "صبح، دوپہر شام". when i am updating or replace with " روزانہ صبح " ... When i enter " روزانہ صبح " in gridview ...but its do not Use new value " روزانہ صبح " instead its again used "صبح، دوپہر شام" and updated ...
i am using Above Code.
Can you tell me what mistake i done in it.

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