|
-
Sep 5th, 2012, 09:34 PM
#1
Thread Starter
Member
[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.
-
Sep 5th, 2012, 10:02 PM
#2
Thread Starter
Member
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.
-
Sep 5th, 2012, 10:16 PM
#3
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)
Last edited by Arve K.; Sep 5th, 2012 at 10:28 PM.
-
Sep 6th, 2012, 08:17 PM
#4
Thread Starter
Member
Re: How to handle foreign characters in write to database (e.g. é, ç, etc)
Thanks, your solujtion worked, but I had to encode UTF7.
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
|