string strWhere = "";
BLL.P_User bll = new BLL.P_User();
DataSet ds =bll.GetList(strWhere);
DataView dv = new DataView();
dv = ds.Tables["tb_user"].DefaultView;
//获取分页总页数
AspNetPager.RecordCount = dv.Count;
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dv;
pds.AllowPaging = true;
pds.CurrentPageIndex = AspNetPager.CurrentPageIndex - 1;
pds.PageSize = AspNetPager.PageSize;
rptUser.DataSource = pds;
rptUser.DataBind();
ds.Tables["tb_user"].Dispose();
调用方法:
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * from tb_user");
if (strWhere.Trim() != "")
{
strSql.Append("where"+strWhere);
}
return DbHelperSQL.Query(strSql.ToString());
}
public static DataSet Query(string SQLString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
DataSet ds = new DataSet();
try
{
connection.Open();
SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);
command.Fill(ds, "ds");
}
catch (System.Data.SqlClient.SqlException ex)
{
throw new Exception(ex.Message);
}
return ds;
}
}
错误:
dv = ds.Tables["tb_user"].DefaultView;
未将对象引用设置到对象的实例
BLL.P_User bll = new BLL.P_User();
DataSet ds =bll.GetList(strWhere);
DataView dv = new DataView();
dv = ds.Tables["tb_user"].DefaultView;
//获取分页总页数
AspNetPager.RecordCount = dv.Count;
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dv;
pds.AllowPaging = true;
pds.CurrentPageIndex = AspNetPager.CurrentPageIndex - 1;
pds.PageSize = AspNetPager.PageSize;
rptUser.DataSource = pds;
rptUser.DataBind();
ds.Tables["tb_user"].Dispose();
调用方法:
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * from tb_user");
if (strWhere.Trim() != "")
{
strSql.Append("where"+strWhere);
}
return DbHelperSQL.Query(strSql.ToString());
}
public static DataSet Query(string SQLString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
DataSet ds = new DataSet();
try
{
connection.Open();
SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);
command.Fill(ds, "ds");
}
catch (System.Data.SqlClient.SqlException ex)
{
throw new Exception(ex.Message);
}
return ds;
}
}
错误:
dv = ds.Tables["tb_user"].DefaultView;
未将对象引用设置到对象的实例
解决方案 »
- 如何定位panel的滚动条的位置
- sqlite 布尔
- 一个关于asp.net2.0三层结构的,比较菜的问题
- sql语句问题
- 点击跳出一个窗口的问题!
- asp.net 如何实现动态创建伸展菜单?
- 谁有上传大文件的事例和代码
- 请教:.NET怎么把web界面和业务逻辑部署到不同服务器上?
- 怎样作到HyperLinkColumn生成的连接后,点击连接,打开新窗口?
- 为何我的TREEVIEW1.NODES.COUNT() 总是为3,而实际树内有2层,共5个结点?
- DataGrid分页,每页都是同样的数据,怎么回事?
- VS无法启动程序“http://localhost:3303/Default.aspx”。没有更多文件。如何解决?急!!!
先断点bll.GetList(strWhere)看return的值
BLL.P_User bll = new BLL.P_User();
DataSet ds =bll.GetList(strWhere);
DataView dv = new DataView();
dv = ds.Tables["tb_user"].DefaultView;
strWhere 为什么要传个空值,既然是空那又何必写?不是多此一举?DataSet ds =bll.GetList(strWhere);ds里没有数据。断点调试
dv = ds.Tables["tb_user"].DefaultView;那你就设个断点看看,到底哪个东西是空的!
是ds 为null,还是说ds是有内容的,但是里面没有tb_user这个表
where没得空格
strSql.Append("where "+strWhere);
strSql.Append("select * from tb_user ");
if (strWhere.Trim() != "")
{
strSql.Append("where "+strWhere);
}
strSql.Append(" where "+strWhere); //拼接字符串,记住前后都要有空格