테이블 (내용, 크기, 너비, 높이 등)에 저장하려는 매개 변수가있는 메모를 말합니다. 는 SQL 문자열 updateNotes을 갖는 :테이블 (sqlite)의 각 행마다 다른 값을 업데이트하십시오.
는UPDATE NOTES
SET
[email protected],
[email protected],
[email protected],
[email protected],
[email protected],
[email protected],
[email protected],
[email protected]
WHERE SESSION [email protected]
public void save()
{
SQLiteConnection conn = new SQLiteConnection(connectionString);
foreach (Note note in notes)
{
using (SQLiteCommand comm = new SQLiteCommand(updateNotes, conn))
{
comm.Parameters.AddWithValue("@content", note.getNoteItemContent());
comm.Parameters.AddWithValue("@posX", note.getSvi().Center.X);
comm.Parameters.AddWithValue("@posY", note.getSvi().Center.Y);
comm.Parameters.AddWithValue("@sid", sid);
comm.Parameters.AddWithValue("@color", note.getColor());
comm.Parameters.AddWithValue("@orientation", note.getSvi().Orientation);
comm.Parameters.AddWithValue("@height", note.getSvi().ActualHeight);
comm.Parameters.AddWithValue("@width", note.getSvi().ActualWidth);
comm.Parameters.AddWithValue("@author", note.getAuthor());
try
{
conn.Open();
comm.ExecuteNonQuery();
comm.Parameters.Clear();
}
catch (Exception e) { Microsoft.Surface.UserNotifications.RequestNotification("Database error", "Could not write to the database:" + e.Message); }
finally
{
if (conn != null) { conn.Close(); }
listLoaded = false;
}
}
}
}
방법은 위의 사실 테이블 만 쿼리 결과 모든 행에 대해 하나 개의 값을 가진 행을 업데이트 않습니다.
해결책으로 나는 먼저 노트 ID를 읽은 다음 iterate (i ++)를 생각했지만 일부 노트 (테이블의 행으로 표시)가 삭제 될 수 있으므로 ID가 반드시 연속 된 번호 매기기를 따르지는 않습니다.
다른 해결책은 주어진 세션 (sid)에 대한 모든 행 (노트)을 데이터베이스에 쿼리하고 해당 ID를 배열에 저장하고 배열에서 id를 찾을 수있는 노트를 업데이트하는 것이 었습니다.
다른 최적화 된 솔루션에 대해 알고 계십니까? 또는 당신은 내가 업데이트 할 행의 ID를 저장하고 쿼리를 적용하기 위해 배열을 사용해야합니다.
감사합니다.
여기서 무엇을하려고하는지 명확하지 않습니다. 아마도 데이터베이스에서 가져 와서 사용자가 편집 한 메모 개체가 있고 이러한 편집 내용을 반영하도록 데이터베이스를 업데이트하려고하는 것 같습니다. 그렇다면 노트 객체가 해당 행의 ID를 포함 할 수 있습니까? – Tom
그게 내가하려는 일이야. 메모는 테이블에 있지만 개체에없는 ID를 가지고 있습니다. 이는 주로 데이터베이스에 의해 할당 된 기본 키이고 자동 증가이기 때문에 작성시 각 메모에 대해이 ID를 가져 오는 방법이 문제였습니다. – user228137
메모 개체를 만들 때 그 당시 데이터베이스 (콘텐츠, 위치 등)에서 데이터를 선택해야합니다. id를 선택해서 notes 객체의 속성에 저장 하는게 어떨까요? 그런 다음 업데이트 할 때 where 절에 id를 포함하고 주어진 노트에 해당하는 하나의 행만 업데이트 할 수 있습니다. – Tom