使用 ADO 记录集向 VB.NET 中的 VFP 数据表添加新记录

发布于 2024-09-06 07:08:47 字数 1062 浏览 4 评论 0原文

我试图使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

胡渣熟男 2024-09-13 07:08:47

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文