0
我正在製作一個包含用戶的遊戲,運行時出現Finisar.SQLite.SQLiteException。這是代碼:將數據打印到sqlite數據庫時發生Finisar.SQLite.SQLiteException
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Finisar.SQLite;
namespace Racing_Manager
{
public partial class SaveNameBox : Form
{
public string command;
public string savedName;
public string firstName;
public string savedTeamName;
public string surname;
public SQLiteConnection sql_con;
public SQLiteCommand sql_cmd;
public SQLiteDataReader DB;
public void setConnection()
{
sql_con = new SQLiteConnection("Data Source=database.sqlite;Version=3;New=False;Compress=True;");
}
public static SaveNameBox create = new SaveNameBox();
public SaveNameBox()
{
InitializeComponent();
}
//Save Name
private void TextBoxSaveName_TextChanged(object sender, EventArgs e)
{
savedName = TextBoxSaveName.Text;
}
//Team Name
private void teamName_TextChanged(object sender, EventArgs e)
{
savedTeamName = teamName.Text;
}
//First Name
private void textBoxFirstName_TextChanged(object sender, EventArgs e)
{
firstName = textBoxFirstName.Text;
}
//Surname
private void textBoxSurname_TextChanged(object sender, EventArgs e)
{
surname = textBoxSurname.Text;
}
//Confirmation
private void confirm_Click(object sender, EventArgs e)
{
command = String.Format("INSERT INTO Users VALUES ({0},{1},{2},{3})", savedName, firstName, surname, savedTeamName);
ExecuteQuery(command);
}
public void ExecuteQuery(string command)
{
setConnection();
sql_con.Open();
sql_cmd.CommandText = command;
}
}
}
唯一的例外是在這條線: sql_con.Open(); 我該如何解決這個問題?非常感謝幫助。
連接字符串是正確的。但它表示該文件不是數據庫(儘管擴展名爲.db)或被加密。我不知道如何解決這個問題。 – aPlutonicCoder