Results 1 to 4 of 4

Thread: [RESOLVED] How to handle foreign characters in write to database (e.g. é, ç, etc)

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    43

    Resolved [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.

  2. #2

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    43

    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.

  3. #3
    Fanatic Member Arve K.'s Avatar
    Join Date
    Sep 2008
    Location
    Kyrksæterøra, Norway
    Posts
    518

    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:
    1. 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.
    Arve K.

    Please mark your thread as resolved and add reputation to those who helped you solve your problem
    Disclaimer: I am not a professional programmer

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    43

    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
  •  



Click Here to Expand Forum to Full Width