本文主要是介绍VB.NET中能不能对DATASET再用SQL语言,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
可以筛选数据,但不能是标准的SQL语句:
Me.DsUserManager1.Tables(0).Select("id > 5 and id <20")
---------------------------------------------------------------
1.筛选:
dataset.tables("tabname").select("id=1")'相当于SQL中WHERE后的条件内容
2.保存到哪?这倒是不知,可能开辟一个内存,也可能是一个临时区....
应该相当于从一个表中select
---------------------------------------------------------------
Select函数返回一个DataRow()对象数组,可用循环方法加入数据集:
dim row as datarow
dim rows() as datarow=Me.DsUserManager1.Tables(0).Select("id > 5 and id <20")
if rows.length>0 then DsUserManager1.table(0).clear'重新导入筛选的数据
for each row in rows
DsUserManager1.table(0).ImportRow(row)
next
---------------------------------------------------------------
ms-help://MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemDataDataTableClassSelectTopic.htm
---------------------------------------------------------------
类似这样
OdbcCommand1.CommandText = "select * from xx"
OdbcDataAdapter1.SelectCommand = OdbcCommand1
OdbcDataAdapter1.Fill(dataset1, "xx")
---------------------------------------------------------------
可以对dataset中的dataview进行筛选。例如:dataview1.rowFilter="Parent_id"=+Parent.id.tostring
dataview排序用dataview1.sort="Parent ASC"
---------------------------------------------------------------
你要在Table中重新定义一次主键才行,如下:
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
这篇关于VB.NET中能不能对DATASET再用SQL语言的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!