有人知道如何用DataTable的SELECT方法查找表的行吗???

njms1984 2003-10-20 09:24:27
有人知道如何用DataTable的SELECT方法查找表的行吗???
有表TABLE
user_id user_ps
1 345
2 223
3 234
用datatable的select方法找出表中的user_id为1和user_ps为345的记录(vb.net)
...全文
138 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
njms1984 2003-10-21
  • 打赏
  • 举报
回复
晕 怎么抄MSDN上的啊
minajo21 2003-10-20
  • 打赏
  • 举报
回复
同意楼上,注意返回的是一个数组

ETstudio 2003-10-20
  • 打赏
  • 举报
回复
dim tmp as new datatable()
dim aa as string =="[user_id]=1 and [user_ps]=345"
dim t as DataRow()=tmp.select(aa)
ETstudio 2003-10-20
  • 打赏
  • 举报
回复
DataTable tmp=new DataTable ();
string aa="[user_id]=1 and [user_ps]=345";
DataRow[] t=tmp.Select (aa);
acewang 2003-10-20
  • 打赏
  • 举报
回复
Private Sub GetRowsByFilter()
Dim t As DataTable
t = DataSet1.Tables("Orders")
' Presuming the DataTable has a column named Date.
Dim strExpr As String
strExpr = "Date > '1/1/00'"
Dim foundRows() As DataRow
' Use the Select method to find all rows matching the filter.
foundRows = t.Select(strExpr)
Dim i As Integer
' Print column 0 of each returned row.
For i = 0 to foundRows.GetUpperBound(0)
Console.WriteLine(foundRows(i)(0))
Next i
End Sub
acewang 2003-10-20
  • 打赏
  • 举报
回复
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

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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