I'm trying to connect to an accounts package (Pegasus Opera) which uses an
old version of Foxpro as the back end database. I've tried 3 different driver
methods to connect to the data:-
1) Using the Oledb for foxpro driver within .NET
"User ID=;DSN=;Cache Authentication=False;Data
Source='{Freetablepath}';Password=;Provider='VFPOLEDB.1';Collating
Sequence=MACHINE;Null=No;Mask Password=False;Mode=Share Deny None;Extended
Properties=;Encrypt Password=False"
2) Using the 'OLEDB driver for ODBC' driver within .NET (As in the example
below) and with the ODBC connection set up using the 'Microsoft Dbase for
VFP' driver
3) Using the'OLEDB driver for ODBC' driver within .NET and with the ODBC
connection set up using the 'Microsoft Visual Foxpro' drivers
The VB.NET code to insert a row into sname is as below.
Dim cmdFox As New OleDb.OleDbCommand
Dim conFox As New
OleDb.OleDbConnection("BackgroundFetch=Yes;DSN={DSNName};UID=;SourceType=DBF;Collate=Machine;SourceDB={free table directory};Exclusive=No"")
Dim strsql As String
conFox.Open()
cmdFox.CommandText = "insert into T_sname (sn_account, sn_name) values " _
& " ('Test1', 'Test Client')"
cmdFox.Connection = conFox
Try
cmdFox.ExecuteNonQuery()
Catch obje As Exception
MsgBox(obje.Message)
End Try
conFox.Close()
In all cases the error is the same, '{fieldname} cannot be a null value'
I have tried inserting default values into all the rest of the fields to try
and get around this ('' for character fields, 0 for numeric fields, .F. for
boolean fields and 'yyyy-mm-dd hh:mm:ss' for datetimes) but I then get a
invalid data type error instead.
Some dbase/foxpro user groups suggest that earlier versions of Foxpro do not
support null values in which case the above should work and may just be
throwing an error because I've got the format of the default values
incorrect. The two fields filled in, in the above example are the only ones
that are required to add a record.
I hope someone can shed some light on this. Thanks in advance.