473,395 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DataView loop and edit?

Dear friends

Dim myDataView as DataView = New DataView(dsData.Tables("tblCustomers"))

myDataView.RowFilter = "City = 'London'"

My question is how to loop through all rows in myDataView and edit the field
fldZipCode so fldZipCode = "9800"

Regards Able
Nov 20 '05 #1
14 9804
Hi Able,

You can loop though any dataview in the normal way
Typed in this message watch errors
\\\
For i as Integer = 0 to myDataView.count - 1
myDataView(i)("fldZipCode")="9800"
Next
///
That is all

I hope this helps?

Cor
Dim myDataView as DataView = New DataView(dsData.Tables("tblCustomers"))

myDataView.RowFilter = "City = 'London'"

My question is how to loop through all rows in myDataView and edit the field fldZipCode so fldZipCode = "9800"

Regards Able

Nov 20 '05 #2
This goes fine
For i as Integer = 0 to myDataView.count - 1
MsgBox(myDataView(i)("fldZipCode"))
Next

but this causes out of range error
For i as Integer = 0 to myDataView.count - 1
myDataView(i)("fldZipCode")="9800"
Next

Regards Able
"Cor Ligthert" <no**********@planet.nl> skrev i melding
news:us**************@TK2MSFTNGP11.phx.gbl...
Hi Able,

You can loop though any dataview in the normal way
Typed in this message watch errors
\\\
For i as Integer = 0 to myDataView.count - 1
myDataView(i)("fldZipCode")="9800"
Next
///
That is all

I hope this helps?

Cor
Dim myDataView as DataView = New DataView(dsData.Tables("tblCustomers"))

myDataView.RowFilter = "City = 'London'"

My question is how to loop through all rows in myDataView and edit the

field
fldZipCode so fldZipCode = "9800"

Regards Able


Nov 20 '05 #3
Hi,

This example uses a dataview dv.

Dim drv As DataRowView

For Each drv In dv
drv.BeginEdit()
drv.Item("PostalCode") = "2345"
drv.EndEdit()
Next

Ken
------------------

"Able" <ab**@epost.no> wrote in message
news:u5*******************@news4.e.nsc.no:
Dear friends

Dim myDataView as DataView = New DataView(dsData.Tables("tblCustomers"))

myDataView.RowFilter = "City = 'London'"

My question is how to loop through all rows in myDataView and edit the
field
fldZipCode so fldZipCode = "9800"

Regards Able


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.0.0 - Release Date: 6/2/2004
Nov 20 '05 #4
My DataView has 3 rows and error occurs on editing second row.

Regards Able

"Ken Tucker [MVP]" <vb***@bellsouth.net> skrev i melding
news:uC**************@tk2msftngp13.phx.gbl...
Hi,

This example uses a dataview dv.

Dim drv As DataRowView

For Each drv In dv
drv.BeginEdit()
drv.Item("PostalCode") = "2345"
drv.EndEdit()
Next

Ken
------------------

"Able" <ab**@epost.no> wrote in message
news:u5*******************@news4.e.nsc.no:
Dear friends

Dim myDataView as DataView = New DataView(dsData.Tables("tblCustomers"))

myDataView.RowFilter = "City = 'London'"

My question is how to loop through all rows in myDataView and edit the
field
fldZipCode so fldZipCode = "9800"

Regards Able


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.0.0 - Release Date: 6/2/2004

Nov 20 '05 #5
What's the data in the PostalCode field of the second row?? Is it Null??
____________________________
The Grim Reaper

"Able" <ab**@epost.no> wrote in message
news:_K*******************@news2.e.nsc.no...
My DataView has 3 rows and error occurs on editing second row.

Regards Able

"Ken Tucker [MVP]" <vb***@bellsouth.net> skrev i melding
news:uC**************@tk2msftngp13.phx.gbl...
Hi,

This example uses a dataview dv.

Dim drv As DataRowView

For Each drv In dv
drv.BeginEdit()
drv.Item("PostalCode") = "2345"
drv.EndEdit()
Next

Ken
------------------

"Able" <ab**@epost.no> wrote in message
news:u5*******************@news4.e.nsc.no:
Dear friends

Dim myDataView as DataView = New DataView(dsData.Tables("tblCustomers"))
myDataView.RowFilter = "City = 'London'"

My question is how to loop through all rows in myDataView and edit the
field
fldZipCode so fldZipCode = "9800"

Regards Able


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.0.0 - Release Date: 6/2/2004


Nov 20 '05 #6
No

"The Grim Reaper" <gr*********@btopenworld.com> skrev i melding
news:c9**********@sparta.btinternet.com...
What's the data in the PostalCode field of the second row?? Is it Null??
____________________________
The Grim Reaper

"Able" <ab**@epost.no> wrote in message
news:_K*******************@news2.e.nsc.no...
My DataView has 3 rows and error occurs on editing second row.

Regards Able

"Ken Tucker [MVP]" <vb***@bellsouth.net> skrev i melding
news:uC**************@tk2msftngp13.phx.gbl...
Hi,

This example uses a dataview dv.

Dim drv As DataRowView

For Each drv In dv
drv.BeginEdit()
drv.Item("PostalCode") = "2345"
drv.EndEdit()
Next

Ken
------------------

"Able" <ab**@epost.no> wrote in message
news:u5*******************@news4.e.nsc.no:
> Dear friends
>
> Dim myDataView as DataView = New DataView(dsData.Tables("tblCustomers")) >
> myDataView.RowFilter = "City = 'London'"
>
> My question is how to loop through all rows in myDataView and edit the > field
> fldZipCode so fldZipCode = "9800"
>
> Regards Able
>

--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.0.0 - Release Date: 6/2/2004



Nov 20 '05 #7
Hi,

Try this. What is the exact error message printed in the output
window.

Dim drv As DataRowView

For Each drv In dv
Try
drv.BeginEdit()
drv.Item("PostalCode") = "2345"
drv.EndEdit()
Catch ex As Exception
Trace.WriteLine(ex.ToString)
End Try
Next

Ken
---------------

"Able" <ab**@epost.no> wrote in message
news:_K*******************@news2.e.nsc.no:
My DataView has 3 rows and error occurs on editing second row.

Regards Able

"Ken Tucker [MVP]" <HYPERLINK
"mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> skrev i melding
news:uC**************@tk2msftngp13.phx.gbl...
Hi,

This example uses a dataview dv.

Dim drv As DataRowView

For Each drv In dv
drv.BeginEdit()
drv.Item("PostalCode") = "2345"
drv.EndEdit()
Next

Ken
------------------

"Able" <HYPERLINK "mailto:ab**@epost.no"ab**@epost.no> wrote in
message
news:u5*******************@news4.e.nsc.no:

Dear friends

Dim myDataView as DataView = New
DataView(dsData.Tables("tblCustomers"))

myDataView.RowFilter = "City = 'London'"

My question is how to loop through all rows in myDataView and edit
the
field
fldZipCode so fldZipCode = "9800"

Regards Able

--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.0.0 - Release Date: 6/2/2004


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.0.0 - Release Date: 6/2/2004
Nov 20 '05 #8
System.IndexOutOfRangeException: It doesnt exist any row at placing 2.

at System.Data.DataView.GetRecord(Int32 recordIndex)

at System.Data.DataView.IsOriginalVersion(Int32 index)

at System.Data.DataRowView.SetColumnValue(DataColumn column, Object value)

at System.Data.DataRowView.set_Item(String property, Object value)

at Test.Form1.btnEdit_Click(Object sender, EventArgs e) in
D:\VBNet\Test\Test\Form1.vb:line 1825

"Ken Tucker [MVP]" <vb***@bellsouth.net> skrev i melding
news:eW**************@tk2msftngp13.phx.gbl...
Hi,

Try this. What is the exact error message printed in the output
window.

Dim drv As DataRowView

For Each drv In dv
Try
drv.BeginEdit()
drv.Item("PostalCode") = "2345"
drv.EndEdit()
Catch ex As Exception
Trace.WriteLine(ex.ToString)
End Try
Next

Ken
---------------

"Able" <ab**@epost.no> wrote in message
news:_K*******************@news2.e.nsc.no:
My DataView has 3 rows and error occurs on editing second row.

Regards Able

"Ken Tucker [MVP]" <HYPERLINK
"mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> skrev i melding
news:uC**************@tk2msftngp13.phx.gbl...
Hi,

This example uses a dataview dv.

Dim drv As DataRowView

For Each drv In dv
drv.BeginEdit()
drv.Item("PostalCode") = "2345"
drv.EndEdit()
Next

Ken
------------------

"Able" <HYPERLINK "mailto:ab**@epost.no"ab**@epost.no> wrote in
message
news:u5*******************@news4.e.nsc.no:

> Dear friends
>
> Dim myDataView as DataView = New
> DataView(dsData.Tables("tblCustomers"))
>
> myDataView.RowFilter = "City = 'London'"
>
> My question is how to loop through all rows in myDataView and edit
> the
> field
> fldZipCode so fldZipCode = "9800"
>
> Regards Able
>

--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.0.0 - Release Date: 6/2/2004


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.0.0 - Release Date: 6/2/2004

Nov 20 '05 #9
Hi Able,

This gives me 3 rows in a datagrid with 9800 London

So there should be something else wrong.

\\\\
Dim dt As New DataTable("tblCustomers")
dt.Columns.Add("fldZipCode")
dt.Columns.Add("City")
For i As Integer = 0 To 2
Dim dr As DataRow = dt.NewRow
dr("City") = "Amsterdam"
dt.Rows.Add(dr)
Dim drt As DataRow = dt.NewRow
drt("City") = "London"
dt.Rows.Add(drt)
Next
Dim dv As New DataView(dt)
dv.RowFilter = "City = 'London'"
For i As Integer = 0 To dv.Count - 1
dv(i)("fldZipCode") = "9800"
Next
DataGrid1.DataSource = dv
///

I hope this helps?

Cor
Nov 20 '05 #10
Has to define my question more accurately:

Dim myDataView as DataView = New DataView(dsData.Tables("tblCustomers"))

This works:
myDataView.RowFilter = "City = 'London'"

For i as Integer = 0 to myDataView.count - 1
myDataView(i)("fldZipCode")="9800"
Next

....but this doesnt:
myDataView.RowFilter = "City = 'London' And fldZipCode = '9000'"

For i as Integer = 0 to myDataView.count - 1
myDataView(i)("fldZipCode")="9800"
Next

Able
"Able" <ab**@epost.no> skrev i melding
news:u5*******************@news4.e.nsc.no...
Dear friends

Dim myDataView as DataView = New DataView(dsData.Tables("tblCustomers"))

myDataView.RowFilter = "City = 'London'"

My question is how to loop through all rows in myDataView and edit the field fldZipCode so fldZipCode = "9800"

Regards Able

Nov 20 '05 #11
Able,
myDataView.RowFilter = "City = 'London' And fldZipCode = '9000'"
myDataView(i)("fldZipCode")="9800"
Because you used fldZipCode in your Filter, As you change the fldZipCode
field the contents of the collection (the items in the DataView) changes.

The easiest way maybe to use DataTable.Select in this case. As
DataTable.Select returns a fixed array of rows, where as the DataView is a
dynamic collection of rows.

Something like:
Dim table As DataTable = dsData.Tables("tblCustomers")
Dim filterExpression As String = "City = 'London' And fldZipCode =
'9000'"
For Each row As DataRow in table.Select(filterExpression)
row("fldZipCode")="9800"
Next

Hope this helps
Jay

"Able" <ab**@epost.no> wrote in message
news:G0*******************@news4.e.nsc.no... Has to define my question more accurately:

Dim myDataView as DataView = New DataView(dsData.Tables("tblCustomers"))

This works:
myDataView.RowFilter = "City = 'London'"

For i as Integer = 0 to myDataView.count - 1
myDataView(i)("fldZipCode")="9800"
Next

...but this doesnt:
myDataView.RowFilter = "City = 'London' And fldZipCode = '9000'"

For i as Integer = 0 to myDataView.count - 1
myDataView(i)("fldZipCode")="9800"
Next

Able
"Able" <ab**@epost.no> skrev i melding
news:u5*******************@news4.e.nsc.no...
Dear friends

Dim myDataView as DataView = New DataView(dsData.Tables("tblCustomers"))

myDataView.RowFilter = "City = 'London'"

My question is how to loop through all rows in myDataView and edit the

field
fldZipCode so fldZipCode = "9800"

Regards Able


Nov 20 '05 #12
In addition to Jay

with a dataview

For i As Integer = dv.Count - 1 to 0 step -1
dv(i)("fldZipCode") = "9800"
Next

Cor
Nov 20 '05 #13
Got it. Thanks a lot.

Regards Able
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> skrev i melding
news:O$**************@tk2msftngp13.phx.gbl...
Able,
myDataView.RowFilter = "City = 'London' And fldZipCode = '9000'"
myDataView(i)("fldZipCode")="9800"


Because you used fldZipCode in your Filter, As you change the fldZipCode
field the contents of the collection (the items in the DataView) changes.

The easiest way maybe to use DataTable.Select in this case. As
DataTable.Select returns a fixed array of rows, where as the DataView is a
dynamic collection of rows.

Something like:
Dim table As DataTable = dsData.Tables("tblCustomers")
Dim filterExpression As String = "City = 'London' And fldZipCode =
'9000'"
For Each row As DataRow in table.Select(filterExpression)
row("fldZipCode")="9800"
Next

Hope this helps
Jay

"Able" <ab**@epost.no> wrote in message
news:G0*******************@news4.e.nsc.no...
Has to define my question more accurately:

Dim myDataView as DataView = New DataView(dsData.Tables("tblCustomers"))

This works:
myDataView.RowFilter = "City = 'London'"

For i as Integer = 0 to myDataView.count - 1
myDataView(i)("fldZipCode")="9800"
Next

...but this doesnt:
myDataView.RowFilter = "City = 'London' And fldZipCode = '9000'"

For i as Integer = 0 to myDataView.count - 1
myDataView(i)("fldZipCode")="9800"
Next

Able
"Able" <ab**@epost.no> skrev i melding
news:u5*******************@news4.e.nsc.no...
Dear friends

Dim myDataView as DataView = New DataView(dsData.Tables("tblCustomers"))
myDataView.RowFilter = "City = 'London'"

My question is how to loop through all rows in myDataView and edit the

field
fldZipCode so fldZipCode = "9800"

Regards Able



Nov 20 '05 #14
Cor,
I was actually thinking of sorting the DataView descending, then only
changing element zero, when I did my initial post.

However now that you got me to actually think of the alternatives, you
wouldn't need the sort at all! :-)

myDataView.RowFilter = "City = 'London' And fldZipCode = '9000'"

Do Until myDataView.Count = 0
myDataView(0)("fldZipCode")="9800"
Loop

I'm sure there are a couple of other methods...

Jay

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OO**************@TK2MSFTNGP11.phx.gbl...
In addition to Jay

with a dataview

For i As Integer = dv.Count - 1 to 0 step -1
dv(i)("fldZipCode") = "9800"
Next

Cor

Nov 20 '05 #15

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

Similar topics

0
by: wackyphill | last post by:
I loop thru a Filtered DataView and update several of the rows in the loop. The problem is once a ropw gets altered the DataView's Count Seems to be altered causing me to access rows that it...
2
by: Alpha | last post by:
I have a window application. In one of the form, a datagrid has a dataview as its datasource. Initial filtering result would give the datavew 3 items. When I double click on the datagrid to edit...
0
by: grolms | last post by:
I must recreated dataview . I am in the designer insert dataview set datasource ... And I set before DataBind datasource on the dataview ... How I recreated dataview. I have dataview in class...
0
by: MichaƂ Januszczyk | last post by:
Is it possible somehow to retreive {data Key Value} based on clicked {datagrid item index} ? Now i'm trying to do this in the following way, but with no effect. Now, Instead of getting value...
8
by: Dave Hagerich | last post by:
I'm using a DataGrid with a DataSet and I'm trying to filter the data being displayed, using the following code as a test: DataView theView = new DataView(theDataSet.Tables); theView.RowFilter =...
1
by: Able | last post by:
Dear friends Two of the columns in the table tblAdressbook is the field "FirstName" and the field "personID". The table is loaded in the dataset myDataset and is sorted by "personID" in the...
0
by: Nathan Franklin | last post by:
Hello Guys, I have been trying to work this our for so long, but I just can't seem to find the answer. I am loading a datatable from a an access database using an oledbdataadapter. I then...
10
by: Marc R. | last post by:
Hi all, I edit records using a form that have multiple control bind on Dataview, But I don't want to update right always to database, I would like to delay until all Changes (add all new...
3
by: =?Utf-8?B?cG1jZ3VpcmU=?= | last post by:
I have a dataset with 3 tables -- 2 Parent tables and 1 table that is a child table of both the parents. I create a dataview on the child table and set the rowfilter to a value which filters the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.