人的想像力太可怕了。 ss.DataSource= 你连接数据库的方法("select top 3 * from 表名"); ss.DataBind();
拜托,我的想法是取出datatable的前三条记录,你自己不看题目就回答,直接就0分啊
select top 3 * from 表名 就这撒
你居然只想绑定前3条,那为什么不读取到datatable就读3条呢?
select(string)方法中的string好像是sql语句的where条件吧? 例子: private void GetRowsByFilter() { DataTable table = DataSet1.Tables["Orders"]; // Presuming the DataTable has a column named Date. string expression; expression = "Date > '1/1/00'"; DataRow[] foundRows; // Use the Select method to find all rows matching the filter. foundRows = table.Select(expression); // Print column 0 of each returned row. for(int i = 0; i < foundRows.Length; i ++) { Console.WriteLine(foundRows[i][0]); } }
myDataColumn = new DataColumn(); myDataColumn.DataType = System.Type.GetType("System.Int32"); myDataColumn.ColumnName = "ID"; myDataColumn.AutoIncrement = true; myDataColumn.AutoIncrementSeed=0; myDataColumn.AllowDBNull = false; myDataColumn.Unique = true; myTable.Columns.Add(myDataColumn); DataRow[] foundRow=myTable.Select("ID<3"); 或 select top 3 * from table
ss.DataBind();
就这撒
例子:
private void GetRowsByFilter()
{
DataTable table = DataSet1.Tables["Orders"];
// Presuming the DataTable has a column named Date.
string expression;
expression = "Date > '1/1/00'";
DataRow[] foundRows; // Use the Select method to find all rows matching the filter.
foundRows = table.Select(expression); // Print column 0 of each returned row.
for(int i = 0; i < foundRows.Length; i ++)
{
Console.WriteLine(foundRows[i][0]);
}
}
myDataColumn.DataType = System.Type.GetType("System.Int32");
myDataColumn.ColumnName = "ID";
myDataColumn.AutoIncrement = true;
myDataColumn.AutoIncrementSeed=0;
myDataColumn.AllowDBNull = false;
myDataColumn.Unique = true;
myTable.Columns.Add(myDataColumn);
DataRow[] foundRow=myTable.Select("ID<3");
或
select top 3 * from table