public override Business GetBusinessByID(int id) { DBCommands.PopulateParams("@BusinessID", id); DataTable businessTable = DBCommands.AdapterFill("p_Business_GetByID"); Business business = new Business(); try { foreach (DataRow row in businessTable.Rows) { business.AppLink = (row["AppLink"] != DBNull.Value) ? row["AppLink"].ToString() : ""; business.AppStatus = (row["AppStatus"] != DBNull.Value) ? row["AppStatus"].ToString() : ""; business.BusinessAddress = (row["BusinessAddress"] != DBNull.Value) ? row["BusinessAddress"].ToString() : ""; business.BusinessEmail = (row["BusinessEmail"] != DBNull.Value) ? row["BusinessEmail"].ToString() : ""; business.BusinessHoursEnd = (row["BusinessHoursEnd"] != DBNull.Value) ? row["BusinessHoursEnd"].ToString() : ""; business.BusinessHoursStart = (row["BusinessHoursStart"] != DBNull.Value) ? row["BusinessHoursStart"].ToString() : ""; business.BusinessID = Convert.ToInt32(row["BusinessID"]); business.BusinessName = (row["BusinessName"] != DBNull.Value) ? row["BusinessName"].ToString() : ""; business.BusinessPhone = (row["BusinessPhone"] != DBNull.Value) ? row["BusinessPhone"].ToString() : ""; business.FacebookUrl = (row["FacebookUrl"] != DBNull.Value) ? row["FacebokUrl"].ToString() : ""; business.ImageGalleryUrl = (row["ImageGalleryUrl"] != DBNull.Value) ? row["ImageGalleryUrl"].ToString() : ""; business.IsPublic = Convert.ToBoolean(row["IsPublic"] != DBNull.Value) ? Convert.ToBoolean(row["IsPublic"]) : false; business.Other = (row["Other"] != DBNull.Value) ? row["Other"].ToString() : ""; business.TypeOfBusiness = (row["TypeOfBusiness"] != DBNull.Value) ? row["TypeOfBusiness"].ToString() : ""; business.user = UserInfoGetByUser(row["UserName"].ToString()); business.WebsiteUrl = (row["WebsiteUrl"] != DBNull.Value) ? row["WebsiteUrl"].ToString() : ""; } } catch (Exception ex) { DBCommands.RecordError(ex); } return(business); }
internal static DataTable AdapterFill(string sprocName) { DataTable dataTable = new DataTable(); try { using (SqlConnection con = new SqlConnection(_Connection)) { SqlCommand cmd = new SqlCommand(sprocName, con); cmd.CommandType = CommandType.StoredProcedure; for (int index = 0; index < _ParamName.Count; index++) { cmd.Parameters.AddWithValue(_ParamName[index], _ParamValue[index]); } using (SqlDataAdapter sda = new SqlDataAdapter(cmd)) { sda.Fill(dataTable); } } } catch (Exception ex) { DBCommands.RecordError(ex); } finally { EmptyParams(); } return(dataTable); }
internal static bool ExecuteNonQuery(string sprocName) { try { using (SqlConnection con = new SqlConnection(_Connection)) { SqlCommand cmd = new SqlCommand(sprocName, con); cmd.CommandType = CommandType.StoredProcedure; for (int index = 0; index < _ParamName.Count; index++) { cmd.Parameters.AddWithValue(_ParamName[index], _ParamValue[index]); } con.Open(); cmd.ExecuteNonQuery(); return(true); } } catch (Exception ex) { DBCommands.RecordError(ex); return(false); } finally { EmptyParams(); } }
internal static string ExecuteScalar(string sprocName) { try { using (SqlConnection con = new SqlConnection(_Connection)) { SqlCommand cmd = new SqlCommand(sprocName, con); cmd.CommandType = CommandType.StoredProcedure; for (int index = 0; index < _ParamName.Count; index++) { cmd.Parameters.AddWithValue(_ParamName[index], _ParamValue[index]); } con.Open(); var result = cmd.ExecuteScalar(); if (result != null) { return(result.ToString()); } else { return(null); } } } catch (Exception ex) { DBCommands.RecordError(ex); return(null); } finally { EmptyParams(); } }