基於 MySQL Connector /net driver 之 C# 存取 MySQL 範例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
namespace wap5
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void bT1_Click(object sender, EventArgs e)
{
MySqlConnection myCon;
MySqlCommand myCmd;
string myConString = "server=localhost;uid=user;pwd=1234;database=localbase;"+
"port=3306;charset=utf8";
try
{
myCon = new MySqlConnection();
myCon.ConnectionString = myConString;
myCon.Open();
myCmd = new MySqlCommand();
myCmd.Connection = myCon;
myCmd.CommandText = "select * from infolook";
MySqlDataReader myDataSet = myCmd.ExecuteReader();
while (myDataSet.Read())
{
dataOut.Text += myDataSet + "<br />";
}
myDataSet.Close();
myCon.Close();
}
catch (MySqlException mye)
{
Response.Write("Error : "+mye.ToString());
}
}
}
}
頁:
[1]