在C#中操作SQLite数据库需要引用System.Data.SQLite
命名空间,然后使用SQLiteConnection和其他相关类来连接、查询和操作数据库。以下是一个简单的示例:
using System.Data.SQLite;
string connectionString = "Data Source=mydatabase.db;Version=3;";
SQLiteConnection connection = new SQLiteConnection(connectionString);
connection.Open();
SQLiteCommand command = new SQLiteCommand("SELECT * FROM mytable", connection);
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader["column1"].ToString());
}
SQLiteCommand insertCommand = new SQLiteCommand("INSERT INTO mytable (column1, column2) VALUES ('value1', 'value2')", connection);
insertCommand.ExecuteNonQuery();
SQLiteCommand updateCommand = new SQLiteCommand("UPDATE mytable SET column1='newvalue' WHERE id=1", connection);
updateCommand.ExecuteNonQuery();
SQLiteCommand deleteCommand = new SQLiteCommand("DELETE FROM mytable WHERE id=1", connection);
deleteCommand.ExecuteNonQuery();
connection.Close();
以上是一个简单的示例,根据实际需求可能需要更复杂的操作,但基本操作原理都是类似的。希望对你有帮助。