Default.aspx.cs
(完整代码) 1KBusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["connstring"].ConnectionString;
DataSet ds = new DataSet();
using (SqlConnection sqlcon = new SqlConnection(constr))
{
SqlDataAdapter sqld = new SqlDataAdapter("select top 5 number,name,address,writer,beijie from book order by beijie desc", sqlcon);
sqld.Fill(ds, "tabbook");
}
gvjieyue.DataSource = ds.Tables["tabbook"].DefaultView;
gvjieyue.DataBind();
if (!Page.IsPostBack)
{
DataBind();
}
}
//GridView数据绑定代码
public void DataBind()
{
DataSet ds = new DataSet();
using (SqlConnection sqlconn = DB.con())
{
SqlDataAdapter sqld = new SqlDataAdapter("select top 5 no,name,sex,number,idcard,jieshu from reader order by jieshu desc", sqlconn);
sqld.Fill(ds);
}
//SqlConnection con = DB.con();//创建数据连接
//string sql = "select no as 管理员编号,userid as 用户名,pwd as 密码 from manage";//sql语句
//SqlCommand cmd = new SqlCommand(sql, con);
//SqlDataAdapter sda = new SqlDataAdapter(cmd);//数据适配器 select
//DataSet ds = new DataSet();
//sda.Fill(ds);//填充数据集
//指定主键
string[] key = { "no" };
gvreader.DataKeyNames = key;
//GridView绑定数据源
gvreader.DataSource = ds.Tables[0].DefaultView;//指定GridView的数据源
gvreader.DataBind();//实现绑定
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。