是什么数据库 sql吗
新建个数据操作类 DBHelp (ls.com 包)
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace ls.com {
///
/// DbHelp 的摘要说明
///
public class DbHelp:IDisposable {
static SqlConnection _sConnection;
static SqlCommand _sCommand;
static SqlDataAdapter _sDataAdapter;
static String conString = "server=.;uid=sa;pwd=;database=pubs";
public DbHelp():this(conString) {}
public DbHelp(String conStr) {
_sConnection = new SqlConnection();
_sConnection.ConnectionString = conStr;
_sCommand = new SqlCommand();
_sCommand.Connection = _sConnection;
_sDataAdapter = new SqlDataAdapter();
_sCommand.Connection.Open();
}
public int ExecuteNoQuery(String sqSta) {
_sCommand.CommandType = CommandType.Text;
_sCommand.CommandText = sqSta;
return _sCommand.ExecuteNonQuery();
}
public DataTable ExecuteQuery(String seSta) {
DataTable tempTable = new DataTable("table");
_sCommand.CommandType = CommandType.Text;
_sCommand.CommandText = seSta;
_sDataAdapter.SelectCommand = _sCommand;
_sDataAdapter.Fill(tempTable);
return tempTable;
}
#region IDisposable 成员
public void Dispose() {
_sDataAdapter.Dispose();
_sCommand.Dispose();
_sConnection.Close();
}
#endregion
}
}
在页面load事件里写
using (ls.com.DbHelp dbh = new ls.com.DbHelp()) {
this.DataList1.DataSource = dbh.ExecuteQuery("select c.passid,c.teacher,s.name
from class as c join student as s
on c.passid = s.passid");
this.DataList1.DataBind();
就好了
这样 datalist 是不能出来出来数据的
如果改成那个 datagrid 那这样就能出现数据 就是把datalist控件换成 datarid 控件
如果一定要 list的话
那就在 设计 里点击 编辑模板
在里面放上几个lable 几个 textbox lable上就固定值 如 姓名
换到 编码 页 在 textbox 的 text 属性 写成
Text='<%#DataBinder.Eval(Container.DataItem,"name")'
其他一样的
就可以完成
不懂再问
string strcon="select c.passid,c.teacher,s.name
from class as c join student as s
on c.passid = s.passid"
//提取数据的连接串
//连接数据库流程话的东西省略
datalist点击右键 编辑模板 里设置邦定和样式