unicode Characters and Sql problem

hi

there is a excel file that uses unicode characters with special language! (farsi)

I have imported the file to Sql, every thing is OK

now I am trying to work with the database in C# but nothing can be match with the characters in database. for example I have added the language in my windows and try to find all the rows that the name field matches with specific name (with farsi characters) but they can not match together. just uppose that I am looking for 'John' and I have at least 10 rows with this name. in select statement I check with 'John'. both in code and sql have the same look but they can not match together and trust the condition. so (0) rows will selected!!!!

on the other hand, when I try to insert a new row or update some rows with code, all the characters who inserted with C# code or SQL Query Analyser appeare like ' ' in the sql table!!

what is the problem what should I do



Answer this question

unicode Characters and Sql problem

  • Javier Martinez

    You may have exported the data to SQL server in a bad manner, so it is not saved with the correct formatting. Try the "SELECT * FROM MyTable" in your c# program to see what is displayed in the datagrid in your program. Then check if your queries are really correct, i.e. you must write string values in quotation marks (" ' ") and non-string values without it (of course I see that you've mentioned you are doing this).

    If non works, post your query here if possible, so we can give a better answer.



  • larsarve

    additional information:

    I have tried to update a column with the other columns! so the data come from the same database and even the same table and I don't touch the data with code. but still the new column have the same problem with ' ' character instead of the right characters!


  • Mark Jewett - MSFT

    hi dear farshad

    thank you for your response. I am familiar with sql and queries. and they are OK, no doubt. geting data from tables are Ok. everything works just fine for example when I get them and place them to dataGrid. but this query will not give me any rows even if there are many persons with this name:

    Select * from myTable where firstName = ' '

    or even:

    Select * from myTable Where firstName like '% %'

    and so on


  • Amit V

    Hi

    It really seems that there is a problem in the formatting of the data saved in sql server, since you cannot get answer even in sql query analyser(am I wrong ) So try re-importing. I'm in a place that do not have sql server, so I can't test exporting from excel (I must say that I've not exported data from excel to sql server before), but as I said, I would retry importing. If I see any other issue I'll let you know.

    cheers,

    farshad



  • stang4lyfe

    hi

    I find the problem! my data field is nvarchar and when I want to use unicode characters I have to use N before it for example:

    Select * from myTable where firstName = N' '

    instead of

    Select * from myTable where firstName = ' '

    and also for updating and so on...

    cheers


  • unicode Characters and Sql problem