Using Find Method On Primary Keys

  • Thread starter Thread starter rnettle
  • Start date Start date
R

rnettle

Can anyone tell me how to use the DataRowCollection.Find Method on 3
primary keys, 2 of the keys are of the String type and the other is of
the DateTime type. I have tried the code below but get the following
error message .

An unhandled exception of type 'System.InvalidCastException' occurred
in system.data.dll

Additional information: Specified cast is not valid.


Dim dr As DataRow
Dim txt(2)as String
txt(0) = "30/07/05"
txt(1) = "FirstName"
txt(2) = "LastName"
dr = dtInfo.Rows.Find(txt)
 
Do the order of array values and the primary columns match? Make sure the
first primary column is of type Date/Time followed by string values (or
reorder the array values accordingly).

Can anyone tell me how to use the DataRowCollection.Find Method on 3
primary keys, 2 of the keys are of the String type and the other is of
the DateTime type. I have tried the code below but get the following
error message .

An unhandled exception of type 'System.InvalidCastException' occurred
in system.data.dll

Additional information: Specified cast is not valid.


Dim dr As DataRow
Dim txt(2)as String
txt(0) = "30/07/05"
txt(1) = "FirstName"
txt(2) = "LastName"
dr = dtInfo.Rows.Find(txt)
 
Hi,

Dim dr As DataRow
Dim txt(2)as Object
txt(0) = DateTime.Parse("07/30/05")
txt(1) = "FirstName"
txt(2) = "LastName"
dr = dtInfo.Rows.Find(txt)


Ken
 
Back
Top