I have read an article about Asp.net and mysql on the Internet. For details about how to install mysql and connect to the MySQL database in. NET, see ASP. NET + MySQL simple illustration getting started.
Here I use EMS Mysql Manager lite tool to manage mysql5.0
:
Here, my database and table have been created. Now open vs. net2003 and create a project named mysqltest.
Now we have installed MySQL Connector/Net
For specific installation method, please see ASP. NET + MySQL simple illustration entry "http://www.yesky.com/431/1944431.shtml
If it is installed by default, you can go to C: \ Program Files \ MySQL Connector Net 1.0.4 \ bin \. NET 1.1 \ find MySql. data. dll, and then copy it to the bin directory under the mysqltest directory
Right-click the data in the toolbox and choose Add/Remove from the shortcut menu.
For example
Select Browse. Under the bin directory of the mysqltest project, select MySql. Data. dll
Reference MySql. Data. dll in the bin directory of the mysqltest project in solution Manager
Add the DataGrid Control to the aspx page
Here is the C # code
Using System. Data;
Using System. Drawing;
Using System. Web;
Using System. Web. SessionState;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. HtmlControls;
Using MySql. Data. MySqlClient;
Namespace mysqltest
{
/// <Summary>
/// Summary of WebForm1.
/// </Summary>
Public class WebForm1: System. Web. UI. Page
{
Protected System. Web. UI. WebControls. DataGrid DataGrid1;
Private void Page_Load (object sender, System. EventArgs e)
{
// Place user code here to initialize the page
MySqlConnection MyConn = new MySqlConnection ("Server = localhost; userid = root; password =; Database = guestbook ");
String SQL = "select * from guestbook ";
MySqlDataAdapter Myda = new MySqlDataAdapter (SQL, MyConn );
DataSet ds = new DataSet ();
Myda. Fill (ds, "guestbook ");
DataGrid1.DataSource = ds. Tables ["guestbook"]. DefaultView;
DataGrid1.DataBind ();
}
# Code generated by region Web Form Designer
Override protected void OnInit (EventArgs e)
{
//
// CODEGEN: This call is required by the ASP. NET Web form designer.
//
InitializeComponent ();
Base. OnInit (e );
}
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void InitializeComponent ()
{
This. Load + = new System. EventHandler (this. Page_Load );
}
# Endregion
}
}