Используя SQLite с приложением C# winforms - несколько основных вопросов?

Для переключения флажка или можно использовать

element.checked = !element.checked;

, таким образом, Вы могли использовать

if (attribute == elementName)
{
    arrChecks[i].checked = !arrChecks[i].checked;
} else {
    arrChecks[i].checked = false;
}
5
задан Franci Penov 9 October 2009 в 04:16
поделиться

2 ответа

  1. Yes. SQLite is an xcopy-deployment database; there's no registration and your app only needs the dll to use it.

  2. The database is specified in the connection string. In this particular case, it's in the test.db3 file in the application working folder.

  3. You might want to cache the connection to the database to avoid the expensive operation of opening it every time you need to access it. Also, I am not sure why you need a transaction, since all you do is just read from the database.

  4. You have two choices - either store the empty database with the precreated schema and copy it to the output dir during your build process; or create a set of SQL scripts to execute against the database from your code on the first connection to the database. Which one you choose depends on whether you want your application to be responsible for creating the schema or your build process.

  5. If you create an empty database with precreated schema, you can add it as a file along your sources and instruct VS to copy it to the output dir (as I already mentioned).

4
ответ дан 14 December 2019 в 13:41
поделиться

Я почти всегда использую using так:

using (DbConnection conn = new SQLiteConnection(...)) {
   using (DbTransaction tran = conn.BeginTransaction()) {
      using (DbCommand comm = conn.CreateCommand()) {
          ...
      }
      tran.Commit();
   }
   conn.Close();
}

Чтобы sqlite работал, вам нужно использовать транзакции для вставки, обновления и удаления, а также использовать параметризованные запросы. Составные запросы выполняются намного медленнее: Как обойти проблему "'" в sqlite и c #?

2
ответ дан 14 December 2019 в 13:41
поделиться
Другие вопросы по тегам:

Похожие вопросы: