我创建了一个类似测验的应用..当我尝试在标签中显示分数时,我收到了此错误:
An unhandled exception of type 'System.Data.SQLite.SQLiteException' occurred in System.Data.SQLite.dll Additional information: database is locked database is locked
我知道哪个是问题,但我不知道如何解决它。 问题肯定在菜单表格('最高父母')。我知道,因为应用程序从测验表单更新数据库,但当它返回并读取数据库,以便我可以更改标签,我得到了该错误。只有当update_score()同时出现在Meniu()中(甚至在Meniu_Load()中)和.ShowDialog()之后
update_score() - 读取数据库并更改标签
结论:我无法在标签中同时显示最高得分:当我打开应用程序以及何时从quizz表单返回时......所以,我必须在showdialog(用户赢了)之后发表评论update_score知道得分时的分数)或Meniu / Meniu_Load(它在开头没有显示)。 我该如何解决?
菜单代码:
public partial class Meniu : Form
{
SQLiteConnection con;
public bool con_opened = false; // tin minte daca am deschis conexiunea
public int bs_lit=0, bs_info = 0;
public Meniu()
{
//this.StartPosition = FormStartPosition.CenterScreen;
InitializeComponent();
con_opened=false;
update_score();
}
private void Meniu_Load(object sender, EventArgs e)
{
//con_opened=false;
//update_score();
}
public void db1_read()
{
if (con_opened == false)
{
con = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");//Version=3;
con_opened = true;
con.Open();
}
string sql = "select * from bestscore WHERE materie LIKE 'literatura'";
SQLiteCommand command = new SQLiteCommand(sql, con);
SQLiteDataReader reader = command.ExecuteReader();
reader.Read();
bs_lit = Int32.Parse(reader[1].ToString());
command.Dispose();
sql = "select * from bestscore WHERE materie LIKE 'informatica'";
SQLiteCommand cmd = new SQLiteCommand(sql, con);
SQLiteDataReader rdr = cmd.ExecuteReader();
rdr.Read();
bs_info = Int32.Parse(rdr[1].ToString());
cmd.Dispose();
con.Close();
con_opened = false;
}
private void update_score()
{
db1_read();
lbl_bs_info.Text = bs_info.ToString();
lbl_bs_lit.Text = bs_lit.ToString();
}
private void btn_literatura_testare_Click(object sender, EventArgs e)
{
testare flit = new testare();
this.Hide();
flit.reveal = false;
flit.materie = "literatura";
flit.ShowDialog();
update_score(); // if the function is here and in Meniu()
// or Meniu_load()I receive the error
// if it`s just one of them
//it works just fine
if (flit.reveal == true)
this.Show();
else
Application.Exit();
}
}
谢谢!
答案 0 :(得分:0)
我找到答案:我没有处理读者。现在它有效。
// Go trough every li with #gallerylink inside
$("li #gallerylink").each(function()
{
// Bind click event to it
$(this).parent().on("click", function()
{
// Click the link if the li is clicked
$(this).find("#gallerylink")[0].click();
});
});