Ok, trochę kodu z mojego projektu (wyrwane z kontekstu, ale chyba widać co trzeba):
// check if DataFile exists
if (System.IO.File.Exists(dataFile) == false) {
// Magically creates file
connection = new SQLiteConnection("Data Source=" + dataFile);
connection.Open();
// fill with tables
initDataBase();
}
else {
connection = new SQLiteConnection("Data Source=" + dataFile);
connection.Open();
}
private void initDataBase() {
using (SQLiteTransaction transaction = connection.BeginTransaction()) {
using (SQLiteCommand command = connection.CreateCommand()) {
// Create tables
// przyklad:
command.CommandText = @"CREATE TABLE `Songs` (`Song_ID` INTEGER NOT NULL, `Tag_ID` INTEGER NOT NULL, PRIMARY KEY (`Song_ID`, `Tag_ID`))";
command.ExecuteNonQuery();
}
transaction.Commit();
}
}
Zapytanie:
using (SQLiteTransaction transaction = connection.BeginTransaction()) {
using (SQLiteCommand command = connection.CreateCommand()) {
command.CommandText = @"SELECT s.[id] FROM [Songs] s, [Artists] a
WHERE s.[Artist_ID] = a.[ID]
AND s.[Path] = @pPath";
SQLiteParameter pPath = new SQLiteParameter("@pPath");
command.Parameters.Add(pPath);
pPath.Value = path;
object o = command.ExecuteScalar();
song_id = (o != null ? (Int64)o : DBClient.None);
}
transaction.Commit();
}
return song_id;