微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

VB.NET中能不能对DATASET再用SQL语言

可以筛选数据,但不能是标准的sql语句: Me.DsUserManager1.Tables(0).Select("id>5andid<20") --------------------------------------------------------------- 1.筛选: dataset.tables("tabname").select("id=1")'相当于sql中WHERE后的条件内容 2.保存到哪?这倒是不知,可能开辟一个内存,也可能是一个临时区.... 应该相当于从一个表中select --------------------------------------------------------------- Select函数返回一个DaTarow()对象数组,可用循环方法加入数据集: dimrowasdaTarow dimrows()asdaTarow=Me.DsUserManager1.Tables(0).Select("id>5andid<20") ifrows.length>0thenDsUserManager1.table(0).clear'重新导入筛选的数据 foreachrowinrows DsUserManager1.table(0).ImportRow(row) next --------------------------------------------------------------- ms-help://MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemDataDataTableClassSelectTopic.htm --------------------------------------------------------------- 类似这样 OdbcCommand1.CommandText="select*fromxx" OdbcDataAdapter1.SelectCommand=OdbcCommand1 OdbcDataAdapter1.Fill(dataset1,"xx") --------------------------------------------------------------- 可以对dataset中的dataview进行筛选。例如:dataview1.rowFilter="Parent_id"=+Parent.id.tostring dataview排序用dataview1.sort="ParentASC" --------------------------------------------------------------- 你要在Table中重新定义一次主键才行,如下: PrivateSubGetRowsByFilter() DimcustomerTableAsDataTable customerTable=newDataTable("Customers") 'Addcolumns customerTable.Columns.Add("id",GetType(Integer)) customerTable.Columns.Add("name",GetType(String)) 'SetPrimaryKey customerTable.Columns("id").Unique=true customerTable.PrimaryKey=newDataColumn(){customerTable.Columns("id")} 'addtenrows DimidAsInteger Forid=1To10 customerTable.Rows.Add(_ newobject(){id,string.Format("customer{0}",id)}) Nextid customerTable.AcceptChanges() 'addanothertenrows Forid=11To20 customerTable.Rows.Add(_ newobject(){id,id)}) Nextid DimstrExprAsstring DimstrSortAsstring strExpr="id>5" 'SortdescendingbyCompanyNamecolumn. strSort="nameDESC" 'UsetheSelectmethodtofindallrowsmatchingthefilter. DimfoundRowsAsDaTarow()=_ customerTable.Select(strExpr,strSort,DataViewRowState.Added) PrintRows(foundRows,"filteredrows") foundRows=customerTable.Select() PrintRows(foundRows,"allrows") EndSub PrivateSubPrintRows(rows()AsDaTarow,labelAsstring) Console.WriteLine("/n{0}",label) Ifrows.Length<=0Then Console.WriteLine("norowsfound") ExitSub EndIf DimrAsDaTarow DimcAsDataColumn ForEachrInrows ForEachcInr.Table.Columns Console.Write("/t{0}",r(c)) Nextc Console.WriteLine() Nextr EndSub

原文地址:https://www.jb51.cc/vb/262235.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐