使用 ADO 记录集向 VB.NET 中的 VFP 数据表添加新记录
我试图使用 ADO 数据集向 Visual FoxPro 数据表添加一条新记录,但没有成功。代码运行良好,没有异常,但是当我在事后检查 dbf 时,没有新记录。代码片段中显示的 mDataPath 变量是整个数据库的 .dbc 文件的路径。底部关于 For 循环的注释;我正在将传入电子邮件的正文添加到此 MEMO 字段,因此我认为我需要将此字符串的添加分解为 256 个字符的块。任何指导将不胜感激。
cnn1.Open("Driver={Microsoft Visual FoxPro Driver};" & _
"SourceType=DBC;" & _
"SourceDB=" & mDataPath & ";Exclusive=No")
Dim RS As ADODB.RecordsetS = New ADODB.Recordset
RS.Open("select * from gennote", cnn1, 1, 3, 1)
RS.AddNew()
'Assign values to the first three fields
RS.Fields("ignnoteid").Value = NextIDI
RS.Fields("cnotetitle").Value = "'" & mail.Subject & "'"
RS.Fields("cfilename").Value = "''"
'Looping through 254 characters at a time and add the data
'to Ado Field buffer
For i As Integer = 1 To Len(memo) Step liChunkSize
liStartAt = i
liWorkString = Mid(mail.Body, liStartAt, liChunkSize)
RS.Fields("mnote").AppendChunk(liWorkString)
Next
'Update the recordset
RS.Update()
RS.Requery()
RS.Close()
I am trying to add a new record to a Visual FoxPro data table using an ADO dataset with no luck. The code runs fine with no exceptions but when I check the dbf after the fact there is no new record. The mDataPath variable shown in the code snippet is the path to the .dbc file for the entire database. A note about the For loop at the bottom; I am adding the body of incoming emails to this MEMO field so thought I needed to break the addition of this string into 256 character Chunks. Any guidance would be greatly appreciated.
cnn1.Open("Driver={Microsoft Visual FoxPro Driver};" & _
"SourceType=DBC;" & _
"SourceDB=" & mDataPath & ";Exclusive=No")
Dim RS As ADODB.RecordsetS = New ADODB.Recordset
RS.Open("select * from gennote", cnn1, 1, 3, 1)
RS.AddNew()
'Assign values to the first three fields
RS.Fields("ignnoteid").Value = NextIDI
RS.Fields("cnotetitle").Value = "'" & mail.Subject & "'"
RS.Fields("cfilename").Value = "''"
'Looping through 254 characters at a time and add the data
'to Ado Field buffer
For i As Integer = 1 To Len(memo) Step liChunkSize
liStartAt = i
liWorkString = Mid(mail.Body, liStartAt, liChunkSize)
RS.Fields("mnote").AppendChunk(liWorkString)
Next
'Update the recordset
RS.Update()
RS.Requery()
RS.Close()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Microsoft 有一篇与您的问题完全匹配的知识库文章。您的代码与提供的示例之间的唯一主要区别是连接字符串中的 BackgroundFetch 设置。默认情况下,此设置处于启用状态,并且报告会导致许多游标问题。
此外,您可能需要切换到 Visual Foxpro Ole数据库驱动程序。 Visual Foxpro ODBC 驱动程序于 2000 年左右退役。
Microsoft has a Knowledge Base article that matches your question exactly. The only major difference between your code and the example provided is the BackgroundFetch setting in the connection string. This setting is enabled, by default, and has been reported to cause numerous problems with cursors.
In addition, you might want to switch to the Visual Foxpro Ole Db driver. The Visual Foxpro ODBC driver was retired around 2000.