In news: (e-mail address removed),
Trent said:
I'm very new to the .NET environment and am starting to learn on my
home pc. I have some foxpro tables that I want to use. How would I
go about connecting to the data?
Hi Trent,
Accessing FoxPro data is like accessing any other data - you can use either
ODBC or OLE DB. What you do after that depends on what you're doing. Are you
just reading data? Are you updating data? What you really need to understand
is ADO.NET.
Here's some code I wrote to experiment with updating data in a FoxPro Memo
field:
Imports System.Data.OleDb
Module Module1
Sub Main()
' Assumes VFP table TestADO (Id C(10), Memo1 M)
' in database Test.dbc
Dim OleDbConnection1 = New OleDbConnection("User ID=;DSN=;" & _
"Cache Authentication=False;Data Source=""C:\MY DOCUMENTS\VISUAL FOXPRO
PROJECTS\TEST.DBC"";" & _
"Password=;Provider=""VFPOLEDB.1"";Collating Sequence=MACHINE;Mask
Password=False;Mode=Share Deny None;" & _
"Extended Properties=;Encrypt Password=False")
OleDbConnection1.Open()
Dim OleDbCommand1 As OleDbCommand = New OleDbCommand
OleDbCommand1.Connection = OleDbConnection1
OleDbCommand1.CommandType = CommandType.Text
OleDbCommand1.CommandText = _
"INSERT INTO TestADO (Id, Memo1) VALUES (?, ?)"
Dim Parm0 As OleDbParameter = New Data.OleDb.OleDbParameter
Dim Parm1 As OleDbParameter = New Data.OleDb.OleDbParameter
OleDbCommand1.Parameters.Add(Parm0)
OleDbCommand1.Parameters.Add(Parm1)
OleDbCommand1.Parameters(0).Value = "Id Here"
OleDbCommand1.Parameters(1).Value = _
"The quick brown fox jumped over the lazy dog. 50" & _
"The quick brown fox jumped over the lazy dog. 100" & _
"The quick brown fox jumped over the lazy dog. 150" & _
"The quick brown fox jumped over the lazy dog. 200" & _
"The quick brown fox jumped over the lazy dog. 250" & _
"The quick brown fox jumped over the lazy dog. 300" & _
"The quick brown fox jumped over the lazy dog. 350" & _
"The quick brown fox jumped over the lazy dog. 400" & _
"The quick brown fox jumped over the lazy dog. 450" & _
"The quick brown fox jumped over the lazy dog. 500"
Dim RowsAffected As Integer = OleDbCommand1.ExecuteNonQuery()
OleDbConnection1.Close()
End Sub
End Module