如何在(c#)winform程序中 获取ACCESS数据库表中的最后一条记录,并在winform程序中使用该记录的字段值。

我写的一段添加记录的代码:
string strConnect =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\DB\db1.mdb ";
OleDbConnection aConnection = new OleDbConnection(strConnect);
aConnection.Open();

OleDbDataAdapter da = new OleDbDataAdapter(@"select * from table1", aConnection);

DataSet ds = new DataSet();
da.Fill(ds);

OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
da.UpdateCommand = cb.GetUpdateCommand();

DataRow newData = ds.Tables[0].NewRow();
newData["col1"] = tb1.Text;
newData["col2"] = tb2.Text;

ds.Tables[0].Rows.Add(newData);
da.Update(ds);
如果只是两个拆竖岩字段,这段代码添加没有问题。

至于取最旅御后一条记纤戚录的值,可以使用
int total = ds.Tables[0].Rows.Count;
tb1.Text = ds.Tables[0].Rows[total-1]["col1"].ToString();
tb2.Text = ds.Tables[0].Rows[total-1]["col2"].ToString();
怎么觉得你问得跟你的代码不一致呢?
你获取最后一条记录么,毁激就根据Id(pk),select top 1 * 就是了。
你的代码怎么是查询档谈出来的数据又追加一个DataRow,再更新到DataSet中。纤蠢袜
不懂你什么意思。
如果你的主键是自动增长的就用select top1 * from table1 order by ID desc
两个都可以的。
我用MFC的时候一般用的键粗是TreeList,比较好用
现在在学习C#,发现TreeList和MFC差培亮或不多,
DataGridView也比较好用,自己喜好吧。个人感觉还是Winform界面细腻的多。
另外,虚机团上产品团购,超级配伍便宜