Update to Visual FoxPro 6 Table is failing

J

JMark

Everything I've read says the below code should update the foxpro table,
but it doesn't. The dataview and datagrid are being updated, but the
actual foxpro table isn't. The table has 3 fields ( idnum, fname and
lname). The select statement gets the one matching record just fine.
The record in the table has the number 2 in the idnum field, and I'm
trying to change it to the number 90. I also have downloaded and
installed the latest Microsoft VFPOLEDB provider from

http://www.microsoft.com/downloads/...ae1-a59e-965869cb3bc9&displaylang=en#filelist

***** code in button ****

Dim ConnFoxTest As OleDbConnection = New OleDbConnection
Dim SqlCmdFoxTest As OleDbCommand = New OleDbCommand
Dim DaFoxTest As OleDbDataAdapter = New OleDbDataAdapter
Dim DsFoxTest As DataSet = New DataSet
Dim DvFoxTest As DataView = New DataView
Dim idNum As Integer
Dim StrSqlCmdFoxTest As String

StrSqlCmdFoxTest = "Select * From FoxTest where fname='Jeff'"

ConnFoxTest.ConnectionString = "Provider=VFPOLEDB.1;Data
Source=c:\temp\foxtest.dbf;Persist Security Info=False"

ConnFoxTest.Open()
SqlCmdFoxTest.Connection = ConnFoxTest
DaFoxTest.SelectCommand = SqlCmdFoxTest
DaFoxTest.SelectCommand.CommandText = StrSqlCmdFoxTest
DaFoxTest.Fill(DsFoxTest)
DvFoxTest.Table = DsFoxTest.Tables.Item(0)
idNum = DvFoxTest.Item(0).Item("idnum")
' Messagebox shows '2'
MsgBox(Str(idNum))
DvFoxTest(0).BeginEdit()
DvFoxTest(0)("idnum") = 90
DvFoxTest(0).EndEdit()
DsFoxTest.AcceptChanges()
DaFoxTest.Update(DsFoxTest)
idNum = DvFoxTest.Item(0).Item("idnum")
' Messagebox shows '90'
MsgBox(Str(idNum))
' datagrid also shows '90' in the idnum field
DataGrid1.SetDataBinding(DsFoxTest, DsFoxTest.Tables.Item(0).TableName)

DvFoxTest.Dispose()
DsFoxTest.Dispose()
DaFoxTest.Dispose()
SqlCmdFoxTest.Dispose()
ConnFoxTest.Close()

**** end code *******
 
J

JMark

JMark said:
Everything I've read says the below code should update the foxpro table,
but it doesn't. The dataview and datagrid are being updated, but the
actual foxpro table isn't. The table has 3 fields ( idnum, fname and
lname). The select statement gets the one matching record just fine.
The record in the table has the number 2 in the idnum field, and I'm
trying to change it to the number 90. I also have downloaded and
installed the latest Microsoft VFPOLEDB provider from

http://www.microsoft.com/downloads/...ae1-a59e-965869cb3bc9&displaylang=en#filelist


***** code in button ****

Dim ConnFoxTest As OleDbConnection = New OleDbConnection
Dim SqlCmdFoxTest As OleDbCommand = New OleDbCommand
Dim DaFoxTest As OleDbDataAdapter = New OleDbDataAdapter
Dim DsFoxTest As DataSet = New DataSet
Dim DvFoxTest As DataView = New DataView
Dim idNum As Integer
Dim StrSqlCmdFoxTest As String

StrSqlCmdFoxTest = "Select * From FoxTest where fname='Jeff'"

ConnFoxTest.ConnectionString = "Provider=VFPOLEDB.1;Data
Source=c:\temp\foxtest.dbf;Persist Security Info=False"

ConnFoxTest.Open()
SqlCmdFoxTest.Connection = ConnFoxTest
DaFoxTest.SelectCommand = SqlCmdFoxTest
DaFoxTest.SelectCommand.CommandText = StrSqlCmdFoxTest
DaFoxTest.Fill(DsFoxTest)
DvFoxTest.Table = DsFoxTest.Tables.Item(0)
idNum = DvFoxTest.Item(0).Item("idnum")
' Messagebox shows '2'
MsgBox(Str(idNum))
DvFoxTest(0).BeginEdit()
DvFoxTest(0)("idnum") = 90
DvFoxTest(0).EndEdit()
DsFoxTest.AcceptChanges()
DaFoxTest.Update(DsFoxTest)
idNum = DvFoxTest.Item(0).Item("idnum")
' Messagebox shows '90'
MsgBox(Str(idNum))
' datagrid also shows '90' in the idnum field
DataGrid1.SetDataBinding(DsFoxTest, DsFoxTest.Tables.Item(0).TableName)

DvFoxTest.Dispose()
DsFoxTest.Dispose()
DaFoxTest.Dispose()
SqlCmdFoxTest.Dispose()
ConnFoxTest.Close()

**** end code *******


Figured it out, found something on Google. Added these lines.

Dim SqlCmdFoxTest2 As OleDbCommand = New OleDbCommand
Dim StrSqlCmdFoxTest2 As String
StrSqlCmdFoxTest2 = "Update FoxTest Set idnum=90 where fname='Jeff'"
SqlCmdFoxTest2.Connection = ConnFoxTest
SqlCmdFoxTest2.CommandText = StrSqlCmdFoxTest2
DaFoxTest.UpdateCommand = SqlCmdFoxTest2

And also deleted the DsFoxTest.AcceptChanges() line.


Hopes this helps somebody else. Now I just gotta make it work with my
real code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top