我正在尝试将只有一个插入查询的小型C#程序与MS Access数据库连接。我在Internet上跟踪了一些代码,但我做对了。
public partial class Form1 : Form
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\HP\Desktop\victoriy\Database1.accdb);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OleDbCommand cmd = con.CreateCommand();
con.Open();
cmd.CommandText = "Insert into Na(FirstName,LastName)Values('" + textBox1.Text + "','" + textBox2.Text + "')";
cmd.Connection = con;
cmd.ExecuteNonQuery();
MessageBox.Show("Record Submitted", "Congrats");
con.Close();
}
}
}