473,606 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Return DataRow or Row index from DataView

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?
Nov 20 '05 #1
11 27420
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.SqlDataAdapt er1.Fill(Me.Dat aSet11)
'Find the DataRow(s)
Dim dr() As DataRow =
Me.DataSet11.Cu stomers.Select( "contactname='M aria Anders'")
Dim odr As DataRow
For Each odr In dr
Console.WriteLi ne(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.Cu stomers.Select( "contactname='M aria Anders'")
For Each odr In dr
Console.WriteLi ne(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.

Nov 20 '05 #2
Cor
Hi Tim,

In addition to Peter,
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?


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.SqlDataAdapt er1.Fill(Me.Dat aSet11)
dim dv as new dataview(datase t11.tables(0))
dv.rowfilter = "contactname=Ma ria Anders"
if dv.count = 1 then
dv(0).item(myit em) = "What I want"
else
messagebox.show ("There is no or there are more Maria's)
end if
///

Nov 20 '05 #3
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.

Nov 20 '05 #4
Cor
Hi Tim,

There is a typo in my sample.
dv.rowfilter = "contactname='M aria Anders'"

Cor
Nov 20 '05 #5
Cor
Hi Peter,

I think also that the select is better for this.

My answer was a direct answer to the OP, and one of the reasons I did it was
to show to him that your sample was not totally different from his
question.

(More to show him that he did not have to push the datarow back into the
dataset).

Cor
Nov 20 '05 #6
Tim,
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.
Are you searching for a value in the same column each time?

If not then I would probably use the DataTable.Selec t method that Peter
showed.

If you are I would extend Cors example to define the DataView to be sorted
by the value that you are searching for. I would only create this DataView
once when I created the DataTable itself.

Dim table As New DataTable
Dim view As New DataView(table)
view.Sort = "Field to find value in"
Then each time you need to find the value use DataView.Find or
DataView.FindRo ws to process the found rows. Depending on if there will be a
single or multiple values found.

Dim value As String

' handle multiple found rows
For Each viewRow As DataRowView In view.FindRows(v alue)
Dim row As DataRow = viewRow.Row

Next

' handle a single found row
Dim row As DataRow = view(view.Find( value)).Row

David Sceppa's book "Microsoft ADO.NET - Core Reference" from MS Press
covers using a DataView verses using the DataTable.Selec t methods and when
you would or would not use each.

David's book is both a good tutorial on ADO.NET plus a good desk reference
once you know ADO.NET!

Hope this helps
Jay

Hope this helps
Jay

"Tim Frawley" <ti*********@fi shgame.state.ak .us> wrote in message
news:bf******** *************** **@posting.goog le.com... 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?

Nov 20 '05 #7
Cor
Hi Jay B.

You overlooked this sentence in the message from the OP
"the value (which is unique)"

The best method is obvious for this the datatable.selec t, which Peter
showed, combined with the procedure as I did show.

I am not often sure of something that it is "the best" but from this I am.

\\\
Dim dr() As DataRow =Ds.tables(0).S elect("contactn ame='Maria Anders'")
if dr.count = 1 then
dr(0).item(myit em) = "What I want"
else
messagebox.show ("There is no or there are more Maria's")
end if
///

Cor
Nov 20 '05 #8


Wow, Thanks Peter, Cor, and Jay

I have some interesting results from your posts that I would like to
share. First of all, the methods, Table Select and DataView Find
methods both work. What I was not prepared for was the difference in
speed.

When I tested my application using the Table Select method it was taking
approximately 68 seconds to import 200 rows of data from a text file. I
then tested the DataView find method and low and behold, 33 seconds!

I know these times may seem extreme even though for me 33 seconds is an
awesome result. The data is extremely complicated and may contain up to
a hundred values on one row and each value may be inserted into any of
15 tables. We do not know from one value to the next which of those 15
tables will get the value. Thats what you get with Biological data. ;)

The value I am trying to find is in a primary table and it must exist
before the line is allowed to be imported. The value should be unique
but with an Access database anything could happen.

In any case, I want to thank all three of you for helping me out. I now
have a greater understanding of how to find my data and some great
methods for doing the job.

Much appreciated,

Timothy Frawley

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #9
Cor,
Remember that a DataView with the Sort property set effectively creates an
Index on that column, which means the DataView.Find method should out
perform the DataTable.Selec t method! What I'm not sure about is will the
DataTable.Selec t method use the DataView's index if the DataView has been
created?

As I stated, please read Sceppa's book on the merits of both methods.

Hope this helps
Jay
"Cor" <no*@non.com> wrote in message
news:uD******** ******@TK2MSFTN GP12.phx.gbl...
Hi Jay B.

You overlooked this sentence in the message from the OP
"the value (which is unique)"

The best method is obvious for this the datatable.selec t, which Peter
showed, combined with the procedure as I did show.

I am not often sure of something that it is "the best" but from this I am.

\\\
Dim dr() As DataRow =Ds.tables(0).S elect("contactn ame='Maria Anders'")
if dr.count = 1 then
dr(0).item(myit em) = "What I want"
else
messagebox.show ("There is no or there are more Maria's")
end if
///

Cor

Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4125
by: Rodusa | last post by:
I am getting an error on line 133. I am trying to update a datarow using the find method, but it keeps throwing the error below: int ItemKey = dv.Find(Item.inv_mast_uid); DataRow dr; if (ItemKey==-1) // NOT FOUND { dr = dt.NewRow(); dr = Item.inv_mast_uid; dr = 1;
4
13147
by: Hein Albrecht | last post by:
'ello How can I get the DataRow of the DataGrid's SelectedItem for the bound DataView's DataTable? Thanx Hein
3
14678
by: Shravan | last post by:
Hi, How can I bind DataRow array to ComboBox. I tried setting DataSource -> DataRow Array DisplayMember -> ColumnName But it was showing "System.Data.DataRow" for every item in the combobox instead of fetching the
0
1703
by: Ryan | last post by:
Is there a way to get a row's DataView index from the underlying DataTable index. Example DataTable (sorted by key - 1st column) DataView (sorted by second column) Row 0 - A, 2 Row 0 - B, 1 Row 1 - B, 1 Row 1 - A, 2 Row 2 - C, 2 Row 2 - C, 2 I know the key of the row I want and can get the index of that row in the
4
1885
by: Maziar Aflatoun | last post by:
Hi, I have a DataRow that I want to bind to a dropdown list. I have 2 columns (TypeName, TypeValue). When do ddlNewAttribute.DataSource = drAttrValues; ddlNewAttribute.DataBind(); How do I go about binding to a specific column (TypeValue)?
13
1643
by: MadCrazyNewbie | last post by:
Hey Group, I wondered if somebody would be so kind as to help me? Im having trouble with DataViews and DataRows:( I just don`t understand, so I wondered if somebody would be so kind enought to modify my code below to include Datarows and Dataviews and maybe explain a little aswell? Many Thanks
1
3223
by: Ryan Liu | last post by:
Hi, When my code run to DataRow.Delete() It throws: System.ArgumentOutOfRangeException: Non-negative number required. Parameter name: length at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array
8
11921
by: kimtherkelsen | last post by:
Hi, I do this: this.comboBox.DataSource = myDataSet.Tables.Select("location_key = " + selectedLocationKey); this.comboBox.DisplayMember = "text"; this.comboBox.ValueMember = "subcustomer_location_key"; but get an exception when setting the value member. Unfortunately there
5
39635
by: Rainer Queck | last post by:
Hello NG, what would be the best way to locate a DataRrow in a DataGridView? I have by DataTable.Select a bunch of DataRows from a DataTable (which is the data source to the DataGridView). Now I would like to give those related DataGridViewRows a different BackColor. Thanks for hints and help! Rainer
0
8010
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8433
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8300
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5461
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3922
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3969
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2443
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1550
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.