public static bool IsRecordExists(string tableName, string[] columnName, string[] columnValue) { clsDataAccess mobjdata = new clsDataAccess(); bool isExists = false; try { string sQuery = "Select Count(*) from " + tableName + " where "; for (int i = 0; i < columnName.Length; i++) { if (columnValue[i].Trim().Length > 0) { columnValue[i] = columnValue[i].Replace("'", "''"); sQuery += columnName[i] + " = '" + columnValue[i].Trim() + "'"; } else { sQuery += "isnull(" + columnName[i] + ",'') = ''"; } if (i < (columnName.Length - 1)) { sQuery += " and "; } } int cnt = ConvertToInt(mobjdata.ExecuteScalar(sQuery)); if (cnt > 0) { isExists = true; } else { isExists = false; } } catch (Exception ex) { //Logger.Log("AutoNet.Common.Commons -GetColValue(string tableName, string glCode, string searchColName, string retColName)", ex); isExists = false; } return(isExists); }
public static bool IsRecordExists(string tableName, string columnName, string columnValue) { clsDataAccess mobjdata = new clsDataAccess(); bool isExists = false; try { string sQuery = "Select Count(*) from " + tableName + " where "; if (columnValue.Trim().Length > 0) { //if (glCode.Contains("'")) //{ columnValue = columnValue.Replace("'", "''"); //} sQuery += columnName + " = '" + columnValue + "'"; } else { sQuery += "isnull(" + columnName + ",'') = ''"; } int cnt = Convert.ToInt32(mobjdata.ExecuteScalar(sQuery)); if (cnt > 0) { isExists = true; } else { isExists = false; } } catch (Exception ex) { //Logger.Log("AutoNet.Common.Commons -GetColValue(string tableName, string glCode, string searchColName, string retColName)", ex); isExists = false; } return(isExists); }