rgn2121
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") & "'")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
For Each row as DataRow in WeekExcelTable.Rows
Do you have an unique id ?
Dim customerRow() As Data.DataRow
customerRow = DataSet1.Tables("Customers ").Select( "CustomerI D = 'ALFKI'")
customerRow(0)("CompanyNam e") = "Updated Company Name"
customerRow(0)("City") = "Seattle"
Dim customerRow() As Data.DataRow
customerRow = DataSet1.Tables("Customers
customerRow(0)("CompanyNam
customerRow(0)("City") = "Seattle"
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?
ASKER
No...unfortunately I don't for what I am doing...
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
And that edits the DataTable correct...not just the DataRow array element?
Normally it should. Try it out
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
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...
ASKER
Thanks...great link!
ASKER