正如我的標題所描述的,我有一個從 SQLite 資料庫中洗掉的問題。讓我解釋。
第一,它是一個 Windows 表單應用程式。
第二個 .NET Framework 4.8
3d Nugget 包 SQLite Core
我的創建、插入、搜索到 db 作業正常。我有一個搜索,它是一個文本框,當用戶搜索某些內容并從 db 取回正確資訊時,它為他們提供了更新(尚未實作)或使用 2 個單獨按鈕洗掉(顯然)的選項。現在,我的 delete 方法從搜索框中獲取值并嘗試洗掉當前行(請注意,搜索值是來自 db 的主鍵)。
當我按下洗掉按鈕時,我的程式凍結而沒有立即顯示錯誤,但一段時間后仍在除錯程序中,它顯示我的資料庫已鎖定。CallStack 說它要睡覺了。該錯誤發生在該cmd.ExecuteNonQuery行。
我已經搜索了所有網路和這里的相關問題,但沒有找到適合我的東西。我在 C# 初學者論壇中有一篇關于同樣問題的公開帖子。還沒有找到解決方案,有些人試圖幫助我。我不太熟悉 SQLite。我希望我提供了足夠的資訊。
這是我目前正在嘗試的。 洗掉.cs
class Delete_Record
{
string path = "Injection_Settings.db";
public static TextBox Search_Box = new TextBox();
public static TextBox mould_code_input = new TextBox();
public static TextBox machine_number_input = new TextBox();
public static TextBox machine_type_input = new TextBox();
public static TextBox supplier_input = new TextBox();
public static ComboBox colour_input = new ComboBox();
public static ComboBox comboBox1 = new ComboBox();
public static ComboBox comboBox2 = new ComboBox();
public static ComboBox comboBox3 = new ComboBox();
public static NumericUpDown numericUpDown1 = new NumericUpDown();
public static NumericUpDown numericUpDown2 = new NumericUpDown();
public static NumericUpDown numericUpDown3 = new NumericUpDown();
public static DateTimePicker dateTimePicker1 = new DateTimePicker();
public static TextBox item_name_input = new TextBox();
public static PictureBox pictureBox1 = new PictureBox();
public static PictureBox pictureBox2 = new PictureBox();
public void Delete_Info_From_DB()
{
int Mould_Code = Int32.Parse(Search_Box.Text);
try
{
using (SQLiteConnection con = new SQLiteConnection(@"Data Source = " path))
{
con.Open();
using (SQLiteCommand cmd = con.CreateCommand())
{
cmd.CommandText = @"DELETE FROM Description WHERE Mould_Code =@Mould_Code";
cmd.Prepare();
cmd.Parameters.AddWithValue("@Mould_Code", Mould_Code);
cmd.ExecuteNonQuery();
if ((cmd.CommandText = @"SELECT * FROM Description WHERE Mould_Code = " Mould_Code "") == null)
{
MessageBox.Show("Επιτυχ?? διαγραφ?.");
mould_code_input.Text = null;
machine_number_input.Text = null;
machine_type_input.Text = null;
supplier_input.Text = null;
colour_input.Text = null;
comboBox1.Text = null;
comboBox2.Text = null;
comboBox3.Text = null;
numericUpDown1.Text = null;
numericUpDown2.Text = null;
numericUpDown3.Text = null;
dateTimePicker1.Text = null;
item_name_input.Text = null;
pictureBox1.Image = null;
pictureBox2.Image = null;
}
}
con.Close();
}
}
catch (Exception)
{
MessageBox.Show("Αποτυχ?α διαγραφ??.");
}
}
}
Form1 中的洗掉按鈕
private void Delete_Record_Click(object sender, EventArgs e)
{
Delete_Record dr = new Delete_Record();
Delete_Record.Search_Box.Text = Search_Box.Text;
Delete_Record.mould_code_input = mould_code_input;
Delete_Record.machine_number_input = machine_number_input;
Delete_Record.machine_type_input = machine_type_input;
Delete_Record.supplier_input = supplier_input;
Delete_Record.colour_input = colour_input;
Delete_Record.comboBox1 = comboBox1;
Delete_Record.comboBox2 = comboBox2;
Delete_Record.comboBox3 = comboBox3;
Delete_Record.numericUpDown1 = numericUpDown1;
Delete_Record.numericUpDown2 = numericUpDown2;
Delete_Record.numericUpDown3 = numericUpDown3;
Delete_Record.dateTimePicker1 = dateTimePicker1;
Delete_Record.item_name_input = item_name_input;
Delete_Record.pictureBox1 = pictureBox1;
Delete_Record.pictureBox2 = pictureBox2;
if (Database_Search.Search_Box.Text != null)
{
dr.Delete_Info_From_DB();
}
}
uj5u.com熱心網友回復:
我發現了我的問題。我忘記在我的搜索方法中關閉 SqliteDataReader。謝謝大家的幫助。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/461826.html
