Sql server to xml string with encoding

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Urban Andersson (anderssonurban_at_hotmail.com)
Date: 06/22/04

  • Next message: M. Zeeshan Mustafa: "Re: Sqlcommand object gives command timeout"
    Date: Tue, 22 Jun 2004 10:30:17 +0200
    
    

    I try to read data from a SQL server and convert it to a xml document string
    where the data itself is saved with different encodings. I figured out how
    to write the correct encoding to the string but it seems that when reading
    from the database the data i converted from it's original econding to UTF-8.
    So when i write the xml string the result will be garbled. This is what I
    have done so far could someone help me to get the data in correct encoding
    from the database?

    SqlConnection con = new
    SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"].ToString
    ());

    SqlDataAdapter da = new SqlDataAdapter("Select * from langlabels where
    language='tr'",con);

    DataSet ds = new DataSet();

    da.Fill(ds);

    System.IO.Stream ms = new System.IO.MemoryStream();

    ds.WriteXml(ms);

    byte[] ba = new byte[ms.Length];

    ms.Position=0;

    ms.Read(ba,0,(int)ms.Length);

    String strXmlDocument =
    System.Text.Encoding.GetEncoding("ISO-8859-9").GetString(ba);


  • Next message: M. Zeeshan Mustafa: "Re: Sqlcommand object gives command timeout"

    Relevant Pages

    • Re: text datatype support
      ... Unicode or in the default character encoding of the database. ... True means that string parameters are sent to SQL Server in ...
      (microsoft.public.sqlserver.jdbcdriver)
    • Re: Why asci-only symbols?
      ... >> Perhaps string equivalence in keys will be treated like numeric equivalence? ... I know typewill be and in itself contain no encoding information now, ... >and a Unicode string, the system default encoding ...
      (comp.lang.python)
    • Re: Byte Array to String
      ... retrieved text will mismatch the original characters. ... encoding the characters. ... Dim strFileData as String ...
      (microsoft.public.dotnet.framework.aspnet)
    • F is evil (was: XML::LibXML UTF-8 toString() -vs- nodeValue())
      ... And with C<use encoding 'utf8';> you'll get the same character string, ... A script is the complete program text, ...
      (comp.lang.perl.misc)
    • Re: how to extend a byte[] array with a null byte?
      ... and need to write it into a database file as a C-style string. ... I simply need to take the bytearray returned by String.getBytesand add one extra byte containing 0 before passing it to the addmethod. ... your example assumes that the default character encoding is a single-byte-per-character encoding. ... You should either standardize on a specific encoding, and explicitly provide that when you call getBytes, or you should save information in the database describing the encoding, so that when the data is retrieved later, it can be properly interpreted. ...
      (comp.lang.java.programmer)