Dataset with Primary key
I am creating a datatable from a xml file, the datatable contains 4 fields, type, name, desc and uniquecode. This table could have 8000-10000 records.
dsTraker.Tables("slookups").ReadXmlSchema("\my documents\slookups.xsd")
dsTraker.Tables("slookups").ReadXml("\my documents\slookups.xml")
I have created a primary key as follows (the xml file is created from a Visual foxpro database and there is no key for this table)
Dim pk(1) As DataColumn
pk(0) = dsTraker.Tables("slookups").Columns("type")
pk(1) = dsTraker.Tables("slookups").Columns("name")
dsTraker.Tables("slookups").PrimaryKey = pk
I need to find a value (glocation) in the slookups table that is scanned into my program.
Public Function VerifyLocation(ByVal glocation As String) As Boolean
Dim dvlookups As DataView
Dim RowFoundIndex As Integer
Dim sql As String
glocation = Trim(glocation)
sql = "Name = " & glocation
dvlookups = New DataView(dsTraker.Tables("slookups"))
dvlookups.Sort = "name"
dvlookups.RowFilter = sql
dvlookups.RowStateFilter = DataViewRowState.CurrentRows
RowFoundIndex = dvlookups.Find(glocation)
If RowFoundIndex = -1 Then
Else
VerifyLocation = True
End If
End Function
Question 1: Since I created the index on dsTraker.Tables("slookups") should that not be inherited my the dataview that I create in the VerifyLocation function?
Question 2: If question 1 above is yes then will the dataview use that key in the find method
I ask these questions because the time it takes to run this is around 20-40 seconds for each find. Any help is appreicated
chuck
Date:Thu, 16 Aug 2007 07:39:27 -0700
Author:
|