下面是我"录入"按钮的代码
private void inputButton_Click(object sender, EventArgs e)
{
string connStr = string.Format(@"Provider=Microsoft.Jet.Oledb.4.0; Data Source={0}\ExerciseData.mdb", Application.StartupPath);
string accStr = "select *from ExcData";
if (MessageBox.Show("您确认要录入吗?", "提示:", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
{
OleDbConnection conn = new OleDbConnection(connStr);
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter(accStr, conn);
DataSet ds = new DataSet();
da.Fill(ds,"ExcData");
DataTable dt = ds.Tables["ExcData"];
DataRow dr = dt.NewRow();
IDtextBox.Text = dr["ID"].ToString();
ContenttextBox.Text = dr["Content"].ToString();
AnswertextBox.Text = dr["Answer"].ToString();
dt.Rows.Add(dr);
OleDbCommandBuilder cmdbuider = new OleDbCommandBuilder(da);
da.Update(ds,"ExcData");
dataGridView1.DataSource = ds.Tables["ExcData"].DefaultView;
conn.Close();
}
不知道哪儿出问题了,急~