Notes for using MySQL in Windows:
1: Download MYSQL. Use GB2312 encoding when installing the configuration to avoid Chinese garbled characters!
2: download and install the corresponding driver MySQLDriver.
3: When writing code, set reference MySQLDriverCS. dll!
//************************************** **************************************** *********
View data in MYSQL: --->
<Form id = "form1" runat = "server">
<Div> </div>
<Asp: TextBox ID = "tbName" runat = "server"> </asp: TextBox>
<Asp: TextBox ID = "tbAddress" runat = "server"> </asp: TextBox>
<Asp: TextBox ID = "tbTelephone" runat = "server"> </asp: TextBox>
<Asp: Button ID = "btnSubmit" runat = "server" OnClick = "btnSubmit_Click" Text = "insert data"/> <br/>
<Div>
<Asp: GridView ID = "gwShow" runat = "server">
</Asp: GridView>
</Div>
</Form>
//**************
Using MySQLDriverCS;
Public partial class _ Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
BindData ();
}
Private void BindData ()
{
MySQLConnection conn = null;
Conn = new MySQLConnection (new MySQLConnectionString ("localhost", "MyTest", "root", "jasenkin"). AsString );
// Name of the local database, username, root Password
Conn. Open ();
MySQLCommand commn = new MySQLCommand ("set names gb2312", conn );
Commn. ExecuteNonQuery (); // set the set names gb2312 to solve the garbled characters.
String SQL = "select * from user ";
MySQLDataAdapter mda = new MySQLDataAdapter (SQL, conn );
DataSet ds = new DataSet ();
Mda. Fill (ds, "tb ");
This. gwShow. DataSource = ds. Tables ["tb"];
GwShow. DataBind ();
Conn. Close ();
}
Protected void btnSubmit_Click (object sender, EventArgs e)
{
MySQLConnection conn = null;
Conn = new MySQLConnection (new MySQLConnectionString ("localhost", "MyTest", "root", "jasenkin"). AsString );
Conn. Open ();
MySQLCommand commn = new MySQLCommand ("set names gb2312", conn );
Commn. ExecuteNonQuery ();
MySQLCommand comm = new MySQLCommand (string. format ("insert into user (name, address, telephone) values ({0}, {1}, {2})", tbName. text. trim (), tbAddress. text. trim (), tbTelephone. text. trim (), conn );
Comm. ExecuteNonQuery ();
Conn. Close ();
BindData ();
}
}