Document directory
Using
System;
Using
System. Data;
Using
System. Data. sqlclient;
Using
System. configuration;
Using
System. Web;
Using
System. Web. Security;
Using
System. Web. UI;
Using
System. Web. UI. webcontrols;
Using
System. Web. UI. webcontrols. webparts;
Using
System. Web. UI. htmlcontrols;
Using
Mysqldrivercs;
Public
Partial class
_ Default: system. Web. UI. Page
{
Protected void
Page_load (Object sender, eventargs E)
{
Mysqlconnection conn = NULL;
Conn = new mysqlconnection (New
Mysqlconnectionstring ("127.0.0.1", "dvbbs", "root ",
(123456 "). asstring );
Conn. open ();
Mysqlcommand commn = new mysqlcommand ("set names
Gb2312 ", Conn );
Commn. executenonquery ();
String SQL = "select
Title, topicid, boardid
, Dateandtime, hits from dv_topic order by dateandtime
Desc limit 10 ";
Mysqldataadapter MDA = new mysqldataadapter (SQL, Conn );
Dataset DS = new
Dataset ();
MDA. Fill (DS, "Table1 ");
This. repeater1.datasource = Ds;
This. repeater1.databind ();
Conn. Close ();
}
}
In this way, you can access Mysql Data in the. NET environment. Before that, you need to make some preparations. Download mysqldrivercs, install it, find mysqldriver. dll in the installation folder, and add and reference mysqldriver. DLL to the project. Maybe you have code for this line
Mysqlcommand commn = new mysqlcommand ("set names
Gb2312 ", Conn );
Commn. executenonquery ();
I don't quite understand. This is because if there is no such sentence, the data read from the database will be garbled if there is any Chinese character, as long as the statement "set names
"Gb2312" can be executed once as an SQL statement.