如何使用gridview 读取数据
2014-09-10 00:00:00 by 【6yang】,
306
visits,
收藏 |
返回
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 MySql.Data;
using MySql.Data.MySqlClient;
using System.Data.SqlClient;
using System.Configuration;
namespace test
{
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string connectionString = @"data source=.SQLEXPRESS;initial catalog=test;persist security info=True;user id=sa;password=123456"; //Pooling=False;
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
Response.Write(conn.State);
SqlCommand cmd = new SqlCommand("select * from admin", conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "admin");
this.GridView1.DataSource = ds.Tables[0].DefaultView; // 需要在index.aspx下创建一个控件.gridview
this.DataBind();
}
protected void s(object sender, EventArgs e)
{
}
protected void lnklogin_Click(object sender, EventArgs e)
{
}
}
}f
share