I want to check duplicate Id in tblStaffDetail before insert data to this table ..
so i write this methord:
| public bool IsexistID(String IsID, StaffDetailInfo objInfo, SqlTransaction sqlTran) { bool blresutl = false; String StrSQL = "SELECT StName FROM TblStaffDetail \r\n" + "WHERE StID=@StID"; try { SqlCommand sqlCom = DBHelper.SQL_CONNECTION.CreateCommand(); sqlCom.CommandText = StrSQL; sqlCom.Transaction = sqlTran; CommandHelper(sqlCom, objInfo);//Make Object from other Methord GetStaffName = sqlCom.ExecuteScalar().ToString(); } catch (Exception ex) { ex.ToString() } if (GetStaffName == null) { blresutl = false; } else { blresutl = true; } return blresutl; } |
this methord is working if the ID is really duplicated , but if ID is not Exist it will catch error , and i can't insert new record ..
I want to kill this catch error ..and not catch if input new data .Please help me
Niradhip ChakrabortyPosted Jun 25, 2009, 2:09 AM
public bool IsexistID(String IsID, StaffDetailInfo objInfo, SqlTransaction sqlTran)
{
bool blresutl = false;
if( IsID != null || IsID !="")
{
String StrSQL = "SELECT StName FROM TblStaffDetail \r\n" +
"WHERE StID=@StID";
try
{
SqlCommand sqlCom = DBHelper.SQL_CONNECTION.CreateCommand();
sqlCom.CommandText = StrSQL;
sqlCom.Transaction = sqlTran;
CommandHelper(sqlCom, objInfo);//Make Object from other Methord
GetStaffName = sqlCom.ExecuteScalar().ToString();
}
catch (Exception ex)
{
ex.ToString()
}
if (GetStaffName == null)
{
blresutl = false;
}
else
{
blresutl = true;
}
}
else
{
blresutl = false;
}
return blresutl;
}