Adding new record to a VFP data table in VB.NET with ADO recordsets
- by Gerry
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()