הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Wednesday, August 17, 2011 5:09 PM
I have two data tables. dtAllResults is the master data table which contains ResultIDs and everything related to each ResultID. dtNoCV is the other data table which only contains ResultIDs. If the ResultID from dtNoCV is located in dtAllResults I want to update some checkbox cells in dtAllResults (as seen below).
I am new to VB.Net and I'm sure there is a better way to do this. Is there?
I'm looking for better performance, because dtNoCV may contain a few hundred ResultIDs and I'm afraid this loop will slow things down.
Private Function prvfnc_UpdateDGVSource(ByRef dtAllResults As DataTable, ByVal dtNoCV As DataTable, ByVal intEnumValue As Integer) As String
Try
Select Case intEnumValue
Case Is = enmProcedure_M.SetNoReportable
For Each drA As DataRow In dtNoCV.Rows
For Each drB As DataRow In dtAllResults.Rows
If drA("ResultID") = drB("ResultID") Then
drB("booNoReportableResult") = True
drB("booReadyToReport") = True
drB("booFinalValue") = True
Exit For
End If
Next drB
Next drA
Return "Success"
Catch ex As Exception
Call pubsub_AppErrorHandler(Me.GetType.Name, System.Reflection.MethodBase.GetCurrentMethod().Name, ex)
Return "Failed"
End Try
End Function
Thanks in Advance,
Ryan H
Ryan
All replies (4)
Tuesday, August 23, 2011 11:40 AM ✅Answered
I believe I have everything working now. Instead of updating the data table directly (shown in code above), I update the data grid view which displays the source data table (dtAllResults). It appears that when you make a change to a data grid view the data source data table is updated automatically as well. I'm new to VB.NET so all these details take time to figure out.
Thanks,
Ryan
Ryan
Thursday, August 18, 2011 6:00 AM
Hi Ryan0827,
Thanks for your post.
I recommend you could join the two datatables using LINQ and loop through the results of the LINQ query and update the changes. More information, please check below two links. Hope they could make you get some ideas.
http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataset/thread/0184b499-b1bd-45e6-b6e0-e82487dd7925
(How to update one datatable using a join to a 2nd datatable)
http://msdn.microsoft.com/en-us/library/bb918093.aspx (How to: Combine Data with LINQ by Using Joins (Visual Basic))
By the way, you could try ADO.NET DataSet forums for more suggestions which mainly discusses about data platform development using ADO.NET DataSet and LINQ to DataSet issues.
If you have any concerns, please feel free to follow up.
Best regards
Liliane Teng [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Monday, August 22, 2011 4:06 AM
Hi Ryan0827,
I am writing to check the status of the issue on your side. Do you have any updates?
Have a nice day.
Best regards
Liliane Teng [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Tuesday, August 23, 2011 2:13 PM
I believe I have everything working now. Instead of updating the data table directly (shown in code above), I update the data grid view which displays the source data table (dtAllResults). It appears that when you make a change to a data grid view the data source data table is updated automatically as well. I'm new to VB.NET so all these details take time to figure out.
Thanks,
Ryan
Ryan
That is called databinding, you see now direct the advantage of that.
In my idea have you answered your question yourself.
Be aware to use the bindingsource endedit before the update. The DataGridView updates its datasource (your datatable) before a row change and that is forced by an endedit of the bindingsource.
:-)
Success
Cor