C# SQLITE-一次打开两个连接(读和写)
我有一个C#程序,它需要从数据库中逐个读取记录,然后对两列进行一些操作,然后在一个新列上写入。 到目前为止,我喜欢这样:C# SQLITE-一次打开两个连接(读和写),c#,sqlite,C#,Sqlite,我有一个C#程序,它需要从数据库中逐个读取记录,然后对两列进行一些操作,然后在一个新列上写入。 到目前为止,我喜欢这样: using (SQLiteConnection conn_write = new SQLiteConnection("Data Source=" + path + ";PRAGMA journal_mode=WAL;")) { conn_write.Open(); SQLiteCommand cmd_write = new SQLiteCommand(conn
using (SQLiteConnection conn_write = new SQLiteConnection("Data Source=" + path + ";PRAGMA journal_mode=WAL;"))
{
conn_write.Open();
SQLiteCommand cmd_write = new SQLiteCommand(conn_write);
using (SQLiteConnection conn_read = new SQLiteConnection("Data Source=" + path + ";PRAGMA journal_mode=WAL;"))
{
conn_read.Open();
SQLiteCommand cmd_read = new SQLiteCommand(conn_read);
SQLiteDataReader reader;
sql_read = "SELECT ID, ETRF2000_FI, ETRF2000_LA FROM Tutto_NonAbolito";
cmd_read.CommandText = sql_read;
reader = cmd_read.ExecuteReader();
while (reader.Read())
{
MobileKat.ALCoord.ETRF200ToLL84(reader.GetDouble(reader.GetOrdinal("ETRF2000_FI")), reader.GetDouble(reader.GetOrdinal("ETRF2000_LA")), ref lon, ref lat);
sql_write = "UPDATE Tutto_NonAbolito SET LL84_LON = " + lon + ", LL84_LAT = " + lat + " WHERE " + reader.GetInt32(reader.GetOrdinal("ID")) + " = ID;";
cmd_write.CommandText = sql_write;
cmd_write.ExecuteReader();
}
conn_read.Close();
}
conn_write.Close();
}
我还尝试添加PRAGMA,但它仍然告诉我数据库文件已锁定。。有没有办法这样做?我不想在数组中保存列,然后打开另一个连接。如果可能的话,我更喜欢“跑着”去做。谢谢 为什么需要两个连接?因为我需要逐行读取第一个读卡器,然后对当前记录的两列进行一些计算,然后更新数据库并在另一列上写入。这并不能回答我的问题。为什么你不能用一个单一的连接呢?