111,129
社区成员
发帖
与我相关
我的任务
分享using System;
using MySql.Data.MySqlClient;
using System.Data;
namespace WebApplication
{
public partial class Personal_info1 : System.Web.UI.Page
{
//数据库连接字符串
public static string constr = "Database='database';Data Source='localhost';User Id='root';charset='gbk';pooling=true";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
MySqlConnection mycon = new MySqlConnection(constr);//实例化一个连接
mycon.Open();//打开数据库连接
//让查询在GridView1中显示
string sql = "select * from info , cnn";
MySqlDataAdapter da = new MySqlDataAdapter();//实例化MySqldataadpter
MySqlCommand cmd1 = new MySqlCommand(sql,mycon);//sql语句
da.SelectCommand = cmd1;//设置为已实例化MySqlDataAdapter的查询命令
DataSet ds1 = new DataSet();//实例化dataset
da.Fill(ds1);//把数据填充到dataset
GridView1.DataSource = ds1.Tables[0];//将数据集绑定GridView1,完成显示
mycon.Close();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}