public bool Insert(MacBLL u) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { String sql = @"INSERT INTO tbl_mac (" + MacName + "," + MacTon + "," + MacLocation + "," + MacLotNo + "," + MacAddedBy + "," + MacAddedDate + ") VALUES" + "(@mac_name," + "@mac_ton," + "@mac_location," + "@mac_lot_no," + "@mac_added_by," + "@mac_added_date)"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@mac_name", u.mac_name); cmd.Parameters.AddWithValue("@mac_ton", u.mac_ton); cmd.Parameters.AddWithValue("@mac_location", u.mac_location); cmd.Parameters.AddWithValue("@mac_lot_no", u.mac_lot_no); cmd.Parameters.AddWithValue("@mac_added_by", u.mac_added_by); cmd.Parameters.AddWithValue("@mac_added_date", u.mac_added_date); conn.Open(); int rows = cmd.ExecuteNonQuery(); //if the query is executed successfully then the rows' value = 0 if (rows > 0) { //query successful isSuccess = true; } else { //Query falled isSuccess = false; } } catch (Exception ex) { Module.Tool tool = new Module.Tool(); tool.saveToTextAndMessageToUser(ex); } finally { conn.Close(); } return(isSuccess); }
public bool Update(MacBLL u) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { String sql = @"UPDATE tbl_mac SET " + MacName + "=@mac_name," + MacTon + "=@mac_ton," + MacLocation + "=@mac_location," + MacUpdatedBy + "=@mac_updated_by," + MacUpdatedDate + "=@mac_updated_date" + " WHERE mac_id=@mac_id"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@mac_id", u.mac_id); cmd.Parameters.AddWithValue("@mac_name", u.mac_name); cmd.Parameters.AddWithValue("@mac_ton", u.mac_ton); cmd.Parameters.AddWithValue("@mac_location", u.mac_location); cmd.Parameters.AddWithValue("@mac_updated_by", u.mac_updated_by); cmd.Parameters.AddWithValue("@mac_updated_date", u.mac_updated_date); conn.Open(); int rows = cmd.ExecuteNonQuery(); //if the query is executed successfully then the rows' value = 0 if (rows > 0) { //query successful isSuccess = true; } else { //Query falled isSuccess = false; } } catch (Exception ex) { Module.Tool tool = new Module.Tool(); tool.saveToText(ex); } finally { conn.Close(); } return(isSuccess); }
public bool Delete(MacBLL u) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { String sql = "DELETE FROM tbl_mac WHERE mac_id=@mac_id"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@mac_id", u.mac_id); conn.Open(); int rows = cmd.ExecuteNonQuery(); //if the query is executed successfully then the rows' value = 0 if (rows > 0) { //query successful isSuccess = true; } else { //Query falled isSuccess = false; } } catch (Exception ex) { Module.Tool tool = new Module.Tool(); tool.saveToText(ex); } finally { conn.Close(); } return(isSuccess); }