ACCESS开发中不能保存数据的问题,请教
我的采用ADO.NET 修改CCESS数据库后,数据无法保存,或者说每次打开数据库后发现恢复到之前的原始状态,对数据库的修改只是在当时有用。我查阅了许多文章,都说是.ldb文件锁定的问题,本人不是很懂,希望大家知道!谢谢!
我的代码:
public void addSoilBasicInfo()
{
//插入样点
string InsertConnectStr = "INSERT INTO SoilBasicInfo VALUES(" +
"'" + textBox1.Text + "'," +
"'" + textBox10.Text + "'," +
"'" + textBox11.Text + "'," +
"'" + textBox12.Text + "'," +
"'" + textBox13.Text + "'," +
"'" + textBox14.Text + "'," +
"'" + comboBox7.Text + "'," +
"'" + comboBox8.Text + "'," +
"'" + comboBox11.Text + "'," +
"'" + textBox19.Text + "'," +
"'" + comboBox6.Text + "'," +
"'" + textBox20.Text + "'," +
"'" + textBox24.Text + "'," +
"'" + textBox23.Text + "'," +
"'" + textBox22.Text + "')";
//连接数据库
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;";
strConn += "Data Source=";
strConn += "PFS1.0.mdb";
myConnection = new OleDbConnection(strConn);
OleDbCommand myCommand = new OleDbCommand(InsertConnectStr, myConnection);
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
MessageBox.Show("数据添加成功!");
}
catch (OleDbException e)
{
MessageBox.Show("数据错误" + e.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
myConnection.Close();
}
}