我有我的sqlite
数据库存储在C:\program-name\db\db.s3db
。 我有一个表members
与约70
记录。所以现在有一个我必须做的程序,它将所有账号从members
表复制到另一个表act_monthly_listings
。SQLite数据库与C#执行非常缓慢
它显示它正在执行,但它的速度很慢。我不知道是否因为我的代码。这里是一个片段:
连接:
private void SetConnection()
{
sql_con = new SQLiteConnection
("Data Source=C:\\credit-union\\db\\cu.s3db;Version=3;New=False;Compress=True;");
}
在ButtonClick代码:
private void button1_Click(object sender, EventArgs e)
{
button1.Text = "Working Please Wait";
string init_month = dtInit.Value.Month.ToString();
string init_yr = dtInit.Value.Month.ToString();
SetConnection();
sql_con.Open();
SQLiteCommand cmd = new SQLiteCommand();
cmd.CommandText = "select ec_no from members";
cmd.Connection = sql_con;
DR = cmd.ExecuteReader();
int count = 0;
while (DR.Read())
{
DR.Read();
this.Text = "Account : " + DR.GetInt32(0).ToString();
string SQL = "INSERT INTO act_monthly_listings (year,month,act) VALUES ("+ init_yr + "," + init_month + "," + DR.GetInt32(0).ToString() + ")";
//Clipboard.SetText(SQL)
if (ExecuteQuery(SQL))
{
count++;
}
}
if(count > 0){
MessageBox.Show("Accounts Initialized!", "Success", MessageBoxButtons.OK,MessageBoxIcon.Information);
}else{
MessageBox.Show("Initialization Failed!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
sql_con.Close();
}
这可能是因为'while',为什么不使用'INSERT INTO -SELECT'来在一次拍摄中完成所有这些操作。 – Aria
如果它确实起作用,那么你只能得到其他所有行,因为你调用了'Read()'两次。 – Crowcoder