title: C# chinese Encoding/Network
body: <p>I have a Client/Server architecture where messages in text-format are exchanged.</p>
  
  <p>For example:</p>
  
  <pre><code>12  2013/11/11  abcd  5
  ^     ^          ^    ^
  int  date      text  int
  </code></pre>
  
  <p>Everything works fine with "normal" text.
  Now this is a chinese project, so they also want so send chinese symbols. Encoding GB18030 or GB2312.</p>
  
  <p>I read the data this way:</p>
  
  <pre><code>char[] dataIn = binaryReader.ReadChars(length);
  </code></pre>
  
  <p>then i create a new string from the char array and convert it to the right data type (int, float, string etc.).</p>
  
  <p>How can I change/enable chinese encoding, or convert the string values to chinese?
  And what would be a good &amp; easy way to test this.
  Thanks.</p>
  
  <p>I tried using something like this</p>
  
  <pre><code>string stringData = new string(dataIn).Trim();
  byte[] data = Encoding.Unicode.GetBytes(stringData);
  stringData = Encoding.GetEncoding("GB18030").GetString(data);
  </code></pre>
  
  <p>Without success.</p>
  
  <p>Also I need to save some text values to MS SQL Server 2008, is this possible - do I need to configurate anything special?</p>
  
  <p>I also tried this example with storing to the database and printing to the console, but I just get ????????</p>
  
  <pre><code>string chinese = "123东北特钢大连新基地testtest"; 
  byte[] utfBytes = Encoding.Unicode.GetBytes(chinese); 
  byte[] chineseBytes = Encoding.Convert(Encoding.Unicode, Encoding.GetEncoding("GB18030"), utfBytes); 
  string msg = Encoding.GetEncoding("GB18030").GetString(chineseBytes);
  </code></pre>
  
  <p><strong>Edit</strong>
  The problem was with the INSERT queries, which I send to the database. I fixed it with using N' before the string.</p>
  
  <pre><code>sqlCommand = string.Format("INSERT INTO uber_chinese (columnName) VALUES(N'{0}')", myChineseString);
  </code></pre>
  
  <p>Also the column dataType has to be nvarchar instead of varchar.</p>