在我的窗口应用程序中,我想在ms-access中插入用户名和密码,但是当我尝试将其插入数据库时,它会显示如下错误。
这是我的插入数据的代码
public partial class Form1 : Form
{
OleDbConnection con;
OleDbCommand com;
string path = "Provider=Microsoft.ACE.OLEDB.10.0; Data Source=|DataDirectory|\\insert.accdb;";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
con = new OleDbConnection(path);
}
private void button1_Click(object sender, EventArgs e)
{
try
{
con = new OleDbConnection(path); // this is modified
con.Open();
string query = "insert into user(username,User_Password) VALUES ('" + textBox1.Text + "','" + textBox2.Text + "')";
com = new OleDbCommand(query);
com.Connection = con;
com.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}