我正在尝试将新记录插入msaccess2003 mdb文件我的版本是VB.net 2005,它不显示任何错误,当我打开我的访问db文件时,没有插入记录,还有我怎样才能格式化它给我错误的日期字段,如何将txtdate.text转换为与ms acess兼容的日期
这是代码
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim ds As New DataSet
Dim db As New ClassDB
ds = db.FetchData("ricemill.mdb", "sales")
Dim anyRow As DataRow = ds.Tables(0).NewRow
Dim mydate As DateTime
Dim cmydate As String
cmydate = txtdate.Text
mydate = DateTime.Parse(mydate)
anyRow("description") = txtdesc.Text
anyRow("date") = DateTime.Parse(txtdate.Text)
anyRow("amount") = txtamount.Text
ds.Tables(0).Rows.Add(anyRow)
ds.Tables(0).AcceptChanges()
ds.AcceptChanges()
MsgBox("Record Added ! ")
End Sub
答案 0 :(得分:1)
您在此处所做的是虚拟地创建了一个新行,并将其添加到您的虚拟数据库(数据集)
acceptchanges方法只更改行与数据集的关系,它将提交更改,因此您的数据集会将该行视为新创建的行,而不是常规行。
你想要的是打开一个连接,在dataAdapter上使用Update命令,这样它(DA)将查看数据集中的所有更改并将它们提交给实际的数据库。
我需要一段时间才能让它工作,大多数情况下,如果它是测试和错误,并阅读大量的博客/互联网信息。
http://msdn.microsoft.com/en-us/library/6264xxbd.aspx
从这里开始,一旦你理解了DA,你就会非常接近你的答案。