OleDbDataAdapte.Update(DataTable)存不住数据,每次重新打开程序数据就又恢复了
这是代码OleDbConnection myConnection5;
OleDbDataAdapter myDA5;
DataTable myDT5;
OleDbCommandBuilder myDC;
OleDbCommand myC;
private void FrmScoreInput_Load(object sender, EventArgs e)
{
myConnection5 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\".\\XKDB.mdb\"");
myDA5 = new OleDbDataAdapter("Select * from ELECTIVE where StudentID=''", myConnection5);
// myC = new OleDbCommand("Select * from ELECTIVE where StudentID=''", myConnection5);
myDC = new OleDbCommandBuilder(myDA5);
// myDA5.SelectCommand.Parameters.Clear();
// myDA5.SelectCommand.Parameters.Add("@StudentID", System.Data.OleDb.OleDbType.Char, 10);
// myDA5.SelectCommand.Parameters["@studentID"].Value = cboCouseList.Text;
myDT5 = new System.Data.DataTable();
myDA5.Fill(myDT5);
dgvStudents.DataSource = myDT5;
lbStuID.DataBindings.Clear();
lbStuName.DataBindings.Clear();
lbClass.DataBindings.Clear();
txtScore.DataBindings.Clear();
lbStuID.DataBindings.Add("Text", myDT5, "StudentID");
lbStuName.DataBindings.Add("Text", myDT5, "StudentName");
lbClass.DataBindings.Add("Text", myDT5, "ClassID");
txtScore.DataBindings.Add("Text", myDT5, "SCORE");
private void tlbLoadData_Click(object sender, EventArgs e)
{
if (cboCouseList.Text == "") { MessageBox.Show("请先选择课程!!!", "警告!", MessageBoxButtons.OK,MessageBoxIcon.Information); }
else
{
myDT5.Clear();
myDA5.SelectCommand.CommandText = "Select * from ELECTIVE where COUSEID='" + cboCouseList.Text.Substring(0, 4) + "'";
myDA5.Fill(myDT5);
//myDT5.Rows[4].BeginEdit();
txtScore.Focus();
}
}
private void tlbStatic_Click(object sender, EventArgs e)
{
if (cboCouseList.Text == "") { MessageBox.Show("请先加载数据!!!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Information); }
else
{
// myDT5.Clear();
myDA5.SelectCommand.CommandText = "Select count(StudentID) from ELECTIVE where SCORE<>0 and COUSEID='" + cboCouseList.Text.Substring(0, 4) + "'";
myConnection5.Open();
string a = myDA5.SelectCommand.ExecuteScalar().ToString();
myConnection5.Close();
// myDT5.Clear();
myDA5.SelectCommand.CommandText = "Select count(StudentID) from ELECTIVE where SCORE=0 and COUSEID='" + cboCouseList.Text.Substring(0, 4) + "'";
myConnection5.Open();
string b = myDA5.SelectCommand.ExecuteScalar().ToString();
myConnection5.Close();
MessageBox.Show("已录入成绩" + a + "人\n零分或未录入成绩" + b + "人", "统计结果!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void tlbSubmitAll_Click(object sender, EventArgs e)
{
if (cboCouseList.Text == "") { MessageBox.Show("请先加载数据!!!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Information); }
else
{
// myDA5.UpdateCommand = myDC.GetUpdateCommand();
myDT5.GetChanges();
myConnection5.Open();
myDA5.Update(myDT5);
myConnection5.Close();
myDT5.AcceptChanges();
MessageBox.Show("成绩提交成功!!","提示!" ,MessageBoxButtons.OK, MessageBoxIcon.Information);
// myDA5.SelectCommand.CommandText = "Select * from ELECTIVE where COUSEID='" + cboCouseList.Text.Substring(0, 4) + "'";
// myDA5.Fill(myDT5);
}
} --------------------编程问答-------------------- 问题已 解决。。。
把数据文件 设置成不要复制 就行了。。
补充:.NET技术 , C#