[MySQL] Chinese alias garbled characters in SQL statements

Source: Internet
Author: User

MySQL DRIVER: http://www.mysql.com/products/connector/, download as needed

I use ASP. NET to decompress the downloaded driver, create a blank web project, reference the extracted mysql. Data. dll, and add a test. aspx file.

The code of the test. aspx. VB file is as follows:

  1. Imports system. Data
  2. Imports system. Data. Common
  3. Imports mysql. Data. mysqlclient
  4. Partial class test
  5. Inherits system. Web. UI. Page
  6. Protected sub page_load (byval sender as object, byval e as system. eventargs) handles me. Load
  7. Dim connection as mysqlconnection
  8. Connection = new mysqlconnection ("Server = localhost; database = webanalytics; uid = root; Pwd =; charset = utf8 ;")
  9. Connection. open ()
  10. Dotest (New mysqlcommand ("select autoid as '2 automatic number 4' from site", connection ))
  11. Dotest (New mysqlcommand ("select 'id' as 'desc description 100' from site;", connection ))
  12. Dotest (New mysqlcommand ("select 'domain' as '3 domain 2domain' from site;", connection ))
  13. Dotest (New mysqlcommand ("select 'explain 'As 'desc description' from site;", connection ))
  14. Connection. Close ()
  15. Connection. Dispose ()
  16. End sub
  17. Private sub dotest (byval cmd as dbcommand)
  18. Dim reader as dbdatareader = cmd. executereader ()
  19. Response. Write ("
  20. While reader. Read
  21. Response. Write ("<p>" & reader. getvalue (0 ))
  22. End while
  23. Reader. Close ()
  24. Cmd. Dispose ()
  25. End sub
  26. End Class

View the result in the browser as follows:

Note: The last piece of data is garbled in the database.

After repeated tests, it is found that the problem occurs in dbdatareader. If only dbdatareader is used. the alias for the Field Obtained by getname () is not garbled. when the data is read and the last read is non-string type, the next time (the connection object is not closed) when you use dbdatareader again to read the field alias, garbled characters (of course, the alias must be in Chinese) will occur ).

The following solutions are available.
1. Close the connection after dbdatareader is used, and then open it again;
2. After dbdatareader reads the data, it reads another string field;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.