从DataView返回DataRow或Row索引 [英] Return DataRow or Row index from DataView

查看:108
本文介绍了从DataView返回DataRow或Row索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在DataSet中返回DataRow或Row Index,其中我试图找到的

值不是主键。


我必须经常这样做,导入文件时超过200次,所以

它需要快速。


我可以使用Dataview过滤值(这是唯一的)和

返回DataRow对象,所以我可以修改它并将它放回到视图基于或以某种方式得到的数据集中的
RowIndex在

中该行对应的DataSet?

I need to return a DataRow or the Row Index in a DataSet wherein the
value I am attempting to find is not a primary key.

I have to do this often, more than 200 times when importing a file so
it needs to be fast.

Could I use a Dataview to filter for the value (which is unique) and
return either the DataRow object so I can modify it and put it back
into the DataSet the view is based on or somehow get the RowIndex in
the DataSet that the row corresponds to?

推荐答案




感谢您在社区中发帖。


首先,我想确认一下我对您的问题的理解。

从您的描述中,我理解你想在一个

数据集中找到一个数据行,并改变数据流。

我完全理解你了吗?如果有任何我误解的地方,请

随时告诉我。


根据我的了解,您可以尝试使用DataTable的Select方法。 br />

Me.SqlDataAdapter1.Fill(Me.DataSet11)

''找到DataRow(s)

Dim dr()As DataRow =

Me.DataSet11.Customers.Select(" contactname =''Maria Anders''")

Dim odr As DataRow

每个odr In博士

Console.WriteLine(odr.Item(1).ToString)

下一页


''更改数据行

odr.Item(1)=" sdfsdf"


''检查数据集中的数据行是否已更改

dr = Me.DataSet11.Customers.Select(" contactname =''Maria Anders''")

For each odr in Dr

Console。 WriteLine(odr.Item(1).ToString)

下一页

请在上面提出我的建议并告诉我它是否有助于解决你的问题

问题。


最好的rega rds,

Peter Huang

微软在线合作伙伴支持


安全! - www.microsoft.com/security

此帖子原样是按原样提供的。没有保证,也没有赋予任何权利。

Hi

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you want to find a datarow in a
dataset, and change the datarow.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

Based on my knowledge, you may try the Select method of DataTable.

Me.SqlDataAdapter1.Fill(Me.DataSet11)
''Find the DataRow(s)
Dim dr() As DataRow =
Me.DataSet11.Customers.Select("contactname=''Maria Anders''")
Dim odr As DataRow
For Each odr In dr
Console.WriteLine(odr.Item(1).ToString)
Next

''Change the datarow
odr.Item(1) = "sdfsdf"

''Check if the datarow has been changed in the dataset
dr = Me.DataSet11.Customers.Select("contactname=''Maria Anders''")
For Each odr In dr
Console.WriteLine(odr.Item(1).ToString)
Next
Please apply my suggestion above and let me know if it helps resolve your
problem.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


你好蒂姆,


除了彼得,
Hi Tim,

In addition to Peter,
我需要在DataSet中返回DataRow或Row Index,其中我试图找到的
值不是主键。
我必须经常这样做,导入文件时要超过200次,所以
需要快速。
我可以使用Dataview来过滤值(这是唯一的)并且
返回DataRow对象,这样我就可以修改它并将它放回到视图基于的DataSet中或以某种方式获取行对应的DataSet中的RowIndex?
I need to return a DataRow or the Row Index in a DataSet wherein the
value I am attempting to find is not a primary key. I have to do this often, more than 200 times when importing a file so
it needs to be fast. Could I use a Dataview to filter for the value (which is unique) and
return either the DataRow object so I can modify it and put it back
into the DataSet the view is based on or somehow get the RowIndex in
the DataSet that the row corresponds to?




数据视图是数据行的视图。 (因此比你简单得多

写)

所以当你在数据视图中有数据行时,你可以用相同的

正如彼得所展示的那样。 (两者都是一种数据集合,

,选择它的名字是这样的)


(彼得做了一个循环函数,但它循环一条记录,那里在我看来

不需要这样做(也没有选择)进一步是这个程序与

数据视图基本上与彼得相同)


我希望这会有所帮助,


Cor


\\\

Me.SqlDataAdapter1.Fill(Me.DataSet11)

dim dv as new dataview(dataset11.tables(0))

dv.rowfilter =" contactname = Maria Anders"

如果dv.count = 1那么

dv(0).item(myitem)="我想要什么>

else

messagebox.show(没有或者还有更多的玛丽亚)

结束如果

///



The dataview is a view on the datarow. (And therefore much simpler than you
write)
So when you have in the dataview the datarow, you can do with that the same
as Peter showed with the select. (both are a kind of datarow collection,
with the select it is named so)

(Peter made a loopfunction, but it loops one record, there is in my opinion
no need to do that(also not with the select) further is this procedure with
the dataview basicly the same as from Peter)

I hope this helps,

Cor

\\\
Me.SqlDataAdapter1.Fill(Me.DataSet11)
dim dv as new dataview(dataset11.tables(0))
dv.rowfilter = "contactname=Maria Anders"
if dv.count = 1 then
dv(0).item(myitem) = "What I want"
else
messagebox.show("There is no or there are more Maria''s)
end if
///


您好Cor,


是的,您的建议是另一种解决方案,但是DataView正在使用

基本上是DataTable的select方法。如果我们使用DataView,我们需要声明一个dataview对象,另外,我使用循环,以防止
从select方法返回多行。


感谢您与我们分享知识。


致以诚挚的问候,


Peter Huang

Microsoft在线合作伙伴支持


安全! - www.microsoft.com/security

此帖子原样是按原样提供的。没有保证,也没有授予任何权利。

Hi Cor,

Yes, your suggestion is another solution, however the DataView is using
the select method of DataTable underlyingly. If we use the DataView, we
need to declare a dataview object, also, I use the loop in case that there
are more than one row returned from select method.

Thank you for sharing the knowledge with us.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


这篇关于从DataView返回DataRow或Row索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆