我试图改进几个月前制作的旧程序,它本质上是一个社交网络应用程序。因此,我试图"写" Microsoft Access(2010)中的一个表中的新行。之前,它工作正常,它根据需要更新/按下按钮。但现在,它不是。
当我按" Post"它遍历代码中的所有行而没有问题/错误,但数据库不会更新。我无法弄清楚为什么不更新,所以非常感谢任何帮助;
private void btnPost_Click(object sender, EventArgs e)
{
String postText = txtPost.Text;
String followingIDStr = cboxFollowing.ValueMember.ToString();
int followingID = Convert.ToInt32(followingIDStr);
con = new OleDbConnection(connectionString);
DataSet ds = new DataSet();
DataRow dRow;
String sql = "SELECT * FROM Post;";
OleDbDataAdapter da = new OleDbDataAdapter(sql, con);
con.Open();
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
DataTable dataTable = new DataTable();
da.Fill(ds, "Post");
dRow = ds.Tables["Post"].NewRow();
dRow[1] = memberID;
dRow[2] = followingID;
dRow[3] = "Text";
dRow[4] = postText;
dRow[5] = DateTime.Today.Date.ToString();
dRow[6] = DateTime.Now.ToString("HH:mm");
dRow[7] = DateTime.Now.ToString("dd/MM/yy HH:mm:ss");
ds.Tables["Post"].Rows.Add(dRow);
cb.DataAdapter.Update(ds.Tables["Post"]);
frmNewsFeed newsFeed = new frmNewsFeed();
newsFeed.memberID = memberID;
this.Close();
newsFeed.Show();
}