asp.net页面中如何实现二次检索的功能?

mx120 2004-11-21 08:25:40
~~
...全文
142 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
huangsuipeng 2004-11-22
  • 打赏
  • 举报
回复
噢!简单来讲,就是使用DataTable的Select方法
dzvsyt 2004-11-22
  • 打赏
  • 举报
回复
''不知楼主说的是不是这样,看看下面的程序

Dim i as integer
For i=0 to Ds.Tables("tables").rows().count-1
If Ds.Tables("tables").rows(i).item("字段")="" then '''查询条件
  ''条件成立
else
 ''条件不成立
 End if 
Next
mx120 2004-11-22
  • 打赏
  • 举报
回复
To tonybaobao(Tony宝宝),如果是大数据量的话,好像你的方法也不太好吧
我现在主要是想知道,一般的二次检索采用什么样的策略:
是保存上一次检索的条件还是保存上一次检索的记录的id,还是有其他的方法
tonybaobao 2004-11-21
  • 打赏
  • 举报
回复
示例
[Visual Basic, C#] 以下示例使用筛选表达式和记录状态来返回 DataRow 对象的数组。
[Visual Basic, C#] 注意 此示例显示如何使用 Select 的一个重载版本。有关其他可用示例,请参阅单独的重载主题。
[Visual Basic]
Private Sub GetRowsByFilter()

Dim customerTable As DataTable
customerTable = new DataTable( "Customers" )

' Add columns
customerTable.Columns.Add( "id", GetType(Integer) )
customerTable.Columns.Add( "name", GetType(String) )

' Set PrimaryKey
customerTable.Columns("id").Unique = true
customerTable.PrimaryKey = new DataColumn() { customerTable.Columns("id") }

' add ten rows
Dim id As Integer
For id = 1 To 10
customerTable.Rows.Add( _
new object() { id, string.Format("customer{0}", id) } )
Next id
customerTable.AcceptChanges()

' add another ten rows
For id = 11 To 20
customerTable.Rows.Add( _
new object() { id, string.Format("customer{0}", id) } )
Next id

Dim strExpr As String
Dim strSort As String

strExpr = "id > 5"
' Sort descending by CompanyName column.
strSort = "name DESC"
' Use the Select method to find all rows matching the filter.
Dim foundRows As DataRow() = _
customerTable.Select( strExpr, strSort, DataViewRowState.Added )

PrintRows( foundRows, "filtered rows")

foundRows = customerTable.Select()
PrintRows( foundRows, "all rows")
End Sub

Private Sub PrintRows( rows() As DataRow, label As String)
Console.WriteLine( "\n{0}", label )
If rows.Length <= 0 Then
Console.WriteLine( "no rows found" )
Exit Sub
End If
Dim r As DataRow
Dim c As DataColumn
For Each r In rows
For Each c In r.Table.Columns
Console.Write( "\t {0}", r(c) )
Next c
Console.WriteLine()
Next r
End Sub
[C#]
private static void GetRowsByFilter()
{

DataTable customerTable = new DataTable( "Customers" );
// Add columns
customerTable.Columns.Add( "id", typeof(int) );
customerTable.Columns.Add( "name", typeof(string) );

// Set PrimaryKey
customerTable.Columns[ "id" ].Unique = true;
customerTable.PrimaryKey = new DataColumn[] { customerTable.Columns["id"] };

// Add ten rows
for( int id=1; id<=10; id++ )
{
customerTable.Rows.Add(
new object[] { id, string.Format("customer{0}", id) } );
}
customerTable.AcceptChanges();

// Add another ten rows
for( int id=11; id<=20; id++ )
{
customerTable.Rows.Add(
new object[] { id, string.Format("customer{0}", id) } );
}

string strExpr;
string strSort;

strExpr = "id > 5";
// Sort descending by column named CompanyName.
strSort = "name DESC";
// Use the Select method to find all rows matching the filter.
DataRow[] foundRows =
customerTable.Select( strExpr, strSort, DataViewRowState.Added );

PrintRows( foundRows, "filtered rows" );

foundRows = customerTable.Select();
PrintRows( foundRows, "all rows" );
}

private static void PrintRows( DataRow[] rows, string label )
{
Console.WriteLine( "\n{0}", label );
if( rows.Length <= 0 )
{
Console.WriteLine( "no rows found" );
return;
}
foreach( DataRow r in rows )
{
foreach( DataColumn c in r.Table.Columns )
{
Console.Write( "\t {0}", r[c] );
}
Console.WriteLine();
}
}
mx120 2004-11-21
  • 打赏
  • 举报
回复
simonzone(去留无意 漫任天边云卷云舒) 讲的就是我的意思,应该怎么实现呢?
simonzone 2004-11-21
  • 打赏
  • 举报
回复
我想楼主的意思是:

1.第一次从数据库取出数据
2.在从取出的数据中取出一部分数据

???
huangsuipeng 2004-11-21
  • 打赏
  • 举报
回复
不明白意思
bearold 2004-11-21
  • 打赏
  • 举报
回复
什么叫二次检索???

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧