ASP.NET/Database
< ASP.NET
ASP.NET示例
编辑using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using MySql.Data;
using MySql.Data.MySqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//string constr = "server=localhost;user=root;database=world;port=3306;password=";
string constr = ConfigurationManager.ConnectionStrings["localMySQL"].ConnectionString.ToString();
MySqlConnection con = new MySqlConnection(constr);
con.Open();
MySqlCommand cmd = new MySqlCommand("select * from city", con);
MySqlDataReader dr = cmd.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
dr.Close();
con.Close();
}
}