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:
- Imports system. Data
- Imports system. Data. Common
- Imports mysql. Data. mysqlclient
- Partial class test
- Inherits system. Web. UI. Page
- Protected sub page_load (byval sender as object, byval e as system. eventargs) handles me. Load
- Dim connection as mysqlconnection
- Connection = new mysqlconnection ("Server = localhost; database = webanalytics; uid = root; Pwd =; charset = utf8 ;")
- Connection. open ()
- Dotest (New mysqlcommand ("select autoid as '2 automatic number 4' from site", connection ))
- Dotest (New mysqlcommand ("select 'id' as 'desc description 100' from site;", connection ))
- Dotest (New mysqlcommand ("select 'domain' as '3 domain 2domain' from site;", connection ))
- Dotest (New mysqlcommand ("select 'explain 'As 'desc description' from site;", connection ))
- Connection. Close ()
- Connection. Dispose ()
- End sub
- Private sub dotest (byval cmd as dbcommand)
- Dim reader as dbdatareader = cmd. executereader ()
- Response. Write ("
- While reader. Read
- Response. Write ("<p>" & reader. getvalue (0 ))
- End while
- Reader. Close ()
- Cmd. Dispose ()
- End sub
- 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;