public void InsertPuzzle(PuzzleInfo p) { var conn = GetConnection(); try { string insertSql = @"INSERT INTO PuzzleInfo (id, type, name, location, room, notes) values (@id, @type, @name, @location, @room, @notes)"; SqlCommand insertCmd = new SqlCommand(insertSql, conn); insertCmd.Parameters.Add("@id", SqlDbType.NVarChar); insertCmd.Parameters.Add("@type", SqlDbType.NVarChar); insertCmd.Parameters.Add("@name", SqlDbType.NVarChar); insertCmd.Parameters.Add("@location", SqlDbType.NVarChar); insertCmd.Parameters.Add("@room", SqlDbType.NVarChar); insertCmd.Parameters.Add("@notes", SqlDbType.NVarChar); insertCmd.Parameters["@id"].Value = p.id; insertCmd.Parameters["@type"].Value = p.type; insertCmd.Parameters["@name"].Value = p.name; insertCmd.Parameters["@location"].Value = p.location; insertCmd.Parameters["@room"].Value = p.room; insertCmd.Parameters["@notes"].Value = p.notes; insertCmd.ExecuteNonQuery(); } finally { ReleaseConnection(conn); } }
public void UpdatePuzzle(PuzzleInfo p) { var conn = GetConnection(); try { string updateSql = @"UPDATE PuzzleInfo SET type=@type, name=@name, location=@location, room=@room, notes=@notes WHERE id=@id"; SqlCommand updateCmd = new SqlCommand(updateSql, conn); updateCmd.Parameters.Add("@id", SqlDbType.NVarChar); updateCmd.Parameters.Add("@type", SqlDbType.NVarChar); updateCmd.Parameters.Add("@name", SqlDbType.NVarChar); updateCmd.Parameters.Add("@location", SqlDbType.NVarChar); updateCmd.Parameters.Add("@room", SqlDbType.NVarChar); updateCmd.Parameters.Add("@notes", SqlDbType.NVarChar); updateCmd.Parameters["@id"].Value = p.id; updateCmd.Parameters["@type"].Value = p.type; updateCmd.Parameters["@name"].Value = p.name; updateCmd.Parameters["@location"].Value = p.location; updateCmd.Parameters["@room"].Value = p.room; updateCmd.Parameters["@notes"].Value = p.notes; updateCmd.ExecuteNonQuery(); } finally { ReleaseConnection(conn); } }
protected void Page_Load(object sender, EventArgs e) { PuzzleInfo result = new PuzzleInfo() { type = Request.Params["type"], name = Request.Params["name"], location = Request.Params["location"], room = Request.Params["room"], notes = Request.Params["notes"], }; // insert / update the puzzle information string id = Request.Params["id"]; if (String.IsNullOrEmpty(id)) { InsertPuzzle(result); } else { result.id = id; UpdatePuzzle(result); } Response.Write(JsonConvert.SerializeObject(result)); }