我不确定我在这里做错了什么 - 在调试器中,对文件名所做的更改是正确地对我从更新命令中提取的数据集进行的,但是当我之后检查数据库时没有改变了……所以我有点困惑……
using (System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=J:\\Physics.mdb"))
{
using (OleDbDataAdapter dbAdapter = new OleDbDataAdapter("select thesisID, filename FROM Theses", con))
{
DataSet ds = new DataSet();
con.Open();
dbAdapter.Fill(ds);
for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
{
ds.Tables[0].Rows[j]["filename"] = ds.Tables[0].Rows[j]["filename"].ToString().Replace(',', '_');
string newFileName = ds.Tables[0].Rows[j]["filename"].ToString();
int ID = Convert.ToInt32(ds.Tables[0].Rows[j]["thesisID"].ToString());
using (OleDbCommand updateCommand = con.CreateCommand())
{
updateCommand.CommandText = "update theses set filename = @newFileName where thesisID = @ID";
updateCommand.Parameters.AddWithValue("@ID", ID);
updateCommand.Parameters.AddWithValue("@newFileName", newFileName);
updateCommand.ExecuteNonQuery();
}
}
con.Close();
}
}