在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();
以上是一个简单的示例,根据实际需求可能需要更复杂的操作,但基本操作原理都是类似的。希望对你有帮助。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: SQLite怎么查询满足条件记录的个数