添加功能如下:
try
{
if(this.comboBox1.Text!=""&this.comboBox2.Text!="")
{
this.oleDbInsertCommand1.CommandText="insert into admin values('"+this.comboBox1.Text.Trim()+"','"+this.comboBox2.Text.Trim()+"')";
this.oleDbInsertCommand1.Connection.Open();
this.oleDbInsertCommand1.ExecuteNonQuery();
this.oleDbInsertCommand1.Connection.Close();
this.dataSet11.Clear();
this.dataSet11.AcceptChanges();
MessageBox.Show("添加记录成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Question);
this.oleDbDataAdapter1.Fill(this.dataSet11);
}
else
{
MessageBox.Show("请将记录信息填写完整!","提示",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
}
catch(Exception E)
{
MessageBox.Show("添加记录发生错误:"+E.Message,"提示",MessageBoxButtons.OK,MessageBoxIcon.Question);
if(this.oleDbConnection1.State==ConnectionState.Open)
{
this.oleDbConnection1.Close();
}
}
如果按你的做法,修改都不怎么好做了。