datalist分页,datatable为数据源,总是出错,提示对象名 'dt' 无效。大家帮忙!
dt是我要帮定的数据源,一datatable
OleDbConnection MyConn = new OleDbConnection( "Provider=SQLOLEDB; Data Source=192.0.0.199;Initial Catalog=datacenter;Persist Security Info=True;User ID=sa;Password=masterkey ");
MyConn.Open();
OleDbDataAdapter MyAdapter = new OleDbDataAdapter();
DataSet myDataSet = new DataSet();
OleDbCommand MyCmd = new OleDbCommand( "select * from dt ", MyConn);
MyAdapter.SelectCommand = MyCmd;
myDataSet.Tables.Add(dt);
int startdata = datasize * (Int32.Parse(pagenum) - 1);
MyAdapter.Fill(myDataSet, startdata, datasize, "result ");
MyConn.Close();
DataList3.DataSource = myDataSet.Tables[ "result "].DefaultView;
DataList3.DataBind();
------解决方案--------------------1.分页不是和
MyAdapter.Fill(myDataSet, startdata, datasize, "result ");
有关的,是你从DataSet里取数据的才要做分页的操作
2.你的数据是SQL Server就不要用OleDbConnection连接,都换成Sqlconnection
------解决方案--------------------OleDbCommand MyCmd = new OleDbCommand( "select * from dt ", MyConn);
你的数据库中没dt这张表,请确认
------解决方案--------------------myDataSet.Tables.Add(dt); //dt DataTable dt = new DataTable()先要初始化变量
------解决方案--------------------myDataSet.Tables.Add(dt);
你还没定义dt是什么呢
这之前 DataTable dt = new DataTable();
dt.TableName = "dt ";