Loeurt

Loeurt

  • NA
  • 5
  • 11.3k

Try Cath , throw Error

Jun 25 2009 12:38 AM
Please our member help me...(SQL server 2005 ,and C# language)
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

Answers (1)