public bool UpdateList(MemoList list) { try { string sql = "update List set title = @title, description = @description where id = @id"; command = DBConnection.GetDbConn().CreateCommand(); command.CommandText = sql; command.Parameters.Clear(); SqlParameter titleParam = new SqlParameter("@title", SqlDbType.VarChar, 50); titleParam.Value = list.Title; SqlParameter descriptionParam = new SqlParameter("@description", SqlDbType.VarChar, 1000); descriptionParam.Value = list.Description; SqlParameter idParam = new SqlParameter("@id", SqlDbType.Int); idParam.Value = list.Id; command.Parameters.Add(titleParam); command.Parameters.Add(descriptionParam); command.Parameters.Add(idParam); command.ExecuteNonQuery(); return(true); } catch (Exception e) { Debug.WriteLine(e.Message); return(false); } }
public bool DeleteList(MemoList list) { try { string sql = "delete from List where id = @id"; command = DBConnection.GetDbConn().CreateCommand(); command.CommandText = sql; command.Parameters.Clear(); SqlParameter idParam = new SqlParameter("@id", SqlDbType.Int); idParam.Value = list.Id; command.Parameters.Add(idParam); command.ExecuteNonQuery(); return(true); } catch (Exception e) { Debug.WriteLine(e.Message); return(false); } }
public int InsertList(MemoList list) { string sql = "insert into List (personid, title, description) values (@personid, @title, @description); SELECT SCOPE_IDENTITY()"; command = DBConnection.GetDbConn().CreateCommand(); command.CommandText = sql; command.Parameters.Clear(); SqlParameter personidParam = new SqlParameter("@personid", SqlDbType.Int); personidParam.Value = list.Person.Id; SqlParameter titleParam = new SqlParameter("@title", SqlDbType.VarChar, 50); titleParam.Value = list.Title; SqlParameter descriptionParam = new SqlParameter("@description", SqlDbType.VarChar, 1000); descriptionParam.Value = list.Description; command.Parameters.Add(personidParam); command.Parameters.Add(titleParam); command.Parameters.Add(descriptionParam); return(Convert.ToInt32(command.ExecuteScalar())); }