A
Andrea Caldarone
Hi all,
look at this piece of routine, dsMAIN.Tables("ForeignKeys") is a DataTable
filled with the data of all the foreignKeys in my SQL Servr 2005 database, I
use this datatable to create the corresponding DataRelation object in my
dataset:
'Loop into database's relation
For Each rRelation In dsMAIN.Tables("ForeignKeys").Rows
With rRelation
'setting relation's parameters
strRName = .Item("PTable") & "_" & .Item("CTable")
PCol =
dsMAIN.Tables(.Item("PTable")).columns(.Item("PColumn"))
CCol =
dsMAIN.Tables(.Item("CTable")).columns(.Item("CColumn"))
'adding the relation to the dataset
dsMAIN.Relations.Add(New DataRelation(strRName, PCol, CCol))
End With
Next
The first time the routine loops it takes a lot of time (up to 3 seconds on
a Celeron 2,5Ghz with 1Gb RAM) at the line:
PCol =
dsMAIN.Tables(.Item("PTable")).columns(.Item("PColumn"))
and also a lot of time at the line:
CCol =
dsMAIN.Tables(.Item("CTable")).columns(.Item("CColumn"))
the other times the routine loops trough theese lines it is very fast...
why?
look at this piece of routine, dsMAIN.Tables("ForeignKeys") is a DataTable
filled with the data of all the foreignKeys in my SQL Servr 2005 database, I
use this datatable to create the corresponding DataRelation object in my
dataset:
'Loop into database's relation
For Each rRelation In dsMAIN.Tables("ForeignKeys").Rows
With rRelation
'setting relation's parameters
strRName = .Item("PTable") & "_" & .Item("CTable")
PCol =
dsMAIN.Tables(.Item("PTable")).columns(.Item("PColumn"))
CCol =
dsMAIN.Tables(.Item("CTable")).columns(.Item("CColumn"))
'adding the relation to the dataset
dsMAIN.Relations.Add(New DataRelation(strRName, PCol, CCol))
End With
Next
The first time the routine loops it takes a lot of time (up to 3 seconds on
a Celeron 2,5Ghz with 1Gb RAM) at the line:
PCol =
dsMAIN.Tables(.Item("PTable")).columns(.Item("PColumn"))
and also a lot of time at the line:
CCol =
dsMAIN.Tables(.Item("CTable")).columns(.Item("CColumn"))
the other times the routine loops trough theese lines it is very fast...
why?