Checking existenz of records in a table

  • Thread starter Thread starter info
  • Start date Start date
I

info

Hi

with the following Code I'm checking if an records with an given ID
exists in a Table.

How can I optimize the code?
Because I run this code as part of an synchronization method it is
called many times.

the first 500 calls takes 36 seconds , the next 500 take 52 seconds!

So I think something is wrong with my code or could get optimized.
Are there perhaps other more performant ways too ?


this.CheckPimExtExistsCmd = new SqlCeCommand("Select 2 as zahl from
kontakte where konextlfdnr=?",program.oDaten.sqlConn);
this.CheckPimExtExistsCmd.Parameters.Add(new
SqlCeParameter("konextlfdnr", SqlDbType.NChar, 10));
this.CheckPimExtExistsCmd.Prepare();

public bool ExistKontaktByExtLfdNr(string tcExtLfdNr)
{
bool llExist = false;
object loValue;

this.CheckPimExtExistsCmd.Parameters["konextlfdnr"].Value =
tcExtLfdNr.Trim().PadLeft(10 , ' ');
loValue = this.CheckPimExtExistsCmd.ExecuteScalar();

try
{

if (int.Parse(loValue.ToString())> 0)
{
llExist = true;
}
else
{
llExist = false;
}

}
catch
{
llExist = false;
}


loValue = null;
return llExist;
}
 
Thanks for this hint I'll try to implement this.

Can you see anything more i can optimize?
I don't unterdstand why the speed decreases in such a heavy way
 
I'd put an index on the konextlfdnr column in your table. The
base table cursor i mention in the last is the absolute fastest way to find
a row in a table in SQL CE.
--
Darren Shaffer
..NET Compact Framework MVP
Principal Architect
Connected Innovation
www.connectedinnovation.com
 
Back
Top