加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-16 23:14:22 所属栏目:大数据 来源:网络整理
导读:可以筛选数据,但不能是标准的SQL语句: Me.DsUserManager1.Tables(0).Select("id5andid20") --------------------------------------------------------------- 1.筛选: dataset.tables("tabname").select("id=1")'相当于SQL中WHERE后的条件内容 2.保存到

可以筛选数据,但不能是标准的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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读