[RESOLVED] How to handle foreign characters in write to database (e.g. é, ç, etc)
I am creating a database from an ASCII text file that contains French language characters such as "é" and "ç", which are represented in the ASCII file as bytes with decimals 130 and 135 respectively. I use a StreamReader to read a line into a String, but when I write the string to the database using an SQLCommand Insert (via code), all these characters are replaced by "?". How do I preserve the original? The relevant database field is of type varchar.
Re: How to handle foreign characters in write to database (e.g. é, ç, etc)
Followup - it seems the problem is with the streamreader, as it reads the string from the text file it replaces the accented characters with question marks. Here is the code:
Dim command As New SqlCommand("INSERT INTO Topics (Topic,TopicEng,TopicFr) VALUES (@Name, @English, @French)", _
connection)
Dim RowCount As Integer = 0
Dim ErrorCount As Integer = 0
Dim Textin As StreamReader
Textin = File.OpenText("C:\Auction\topics.txt")
Do While Textin.Peek <> -1
Dim row As String = Textin.ReadLine
Dim Columns() As String = row.Split(CChar("/")
===
If I set a breakpoint at this line and look at row it has already replaced "é" with "?", for instance.
Re: How to handle foreign characters in write to database (e.g. é, ç, etc)
Make sure you are using the correct encoding in the StreamReader's construction.
vb.net Code:
Dim sr As StreamReader = New StreamReader("C:\Auction\topics.txt", System.Text.Encoding.UTF32)
Re: How to handle foreign characters in write to database (e.g. é, ç, etc)
Thanks, your solujtion worked, but I had to encode UTF7.