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;
}
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;
}