Link to home
Start Free TrialLog in
Avatar of rgn2121
rgn2121Flag for United States of America

asked on

When setting a DataRow = DataTable.Select(), an error message displays.

I have a piece of code like what is below.  I have also looked it up around the web and it seems people are doing it the same way.  I am curious why it will not compile and shows as an error.
Dim tempRow As DataRow
tempRow = WeekExcelTable.Select("ID = '" & drv.Item("ID") & "' AND Num = '" & _
                                                drv.Item("NR") & "'")

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgn2121

ASKER

If I edit the items in tempRow, will it also edit them in the WeekExcelTable?  I am searching for a certain row of data and then I will need to edit it if it is found.

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgn2121

ASKER

I thought tempRow was going to have the usual edit routines...I just realized that since it is an array I don't have those.  Is there a way for me to select a row and edit it without doing:

For Each row as DataRow in WeekExcelTable.Rows
Do you have an unique id ?

Dim customerRow() As Data.DataRow
customerRow = DataSet1.Tables("Customers").Select("CustomerID = 'ALFKI'")

customerRow(0)("CompanyName") = "Updated Company Name"
customerRow(0)("City") = "Seattle"
Avatar of rgn2121

ASKER

OKay...so since I will return only one array item with my Select then I can use index zero if the array and it will update the data in the DataTable correct?
Avatar of rgn2121

ASKER

No...unfortunately I don't for what I am doing...
Avatar of rgn2121

ASKER

My Select though is like what I posted above and I will only return one row with that query above.  So then I can still do the index of the Datarow() and be good with that.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgn2121

ASKER

And that edits the DataTable correct...not just the DataRow array element?
Normally it should. Try it out
Avatar of rgn2121

ASKER

Okay...I was able to do the following which is pretty much the same and it seemed to work very well although I didn't want to take the time to verify all the data as there might be a few things I need to tweak yet.


 Dim tempRow() As DataRow
tempRow = WeekExcelTable.Select("ID = '" & drv.Item("ID") & "' AND Num = '" & _
                                                drv.Item("NR") & "'")
If tempRow.Length > 0 Then
   tempRow(0).BeginEdit()
   ...edit the items...
   tempRow(0).EndEdit()
   tempRow(0).AcceptChanges()
Array.Clear(tempRow, 0, tempRow.Length)
End if

Open in new window

Avatar of rgn2121

ASKER

If you see anything off in that let me know, but at quick glance it seemed to work very well and is a lot less code then what I was doing with the For Each row as DataRow...
Avatar of rgn2121

ASKER

Thanks...great link!