Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

connecting to visual fox pro table

Status
Not open for further replies.

shresthaal

Programmer
Jun 8, 2005
62
0
0
US
i am new to VB.NET. can anyone tell me how to connect to a visual fox pro table and also execute queries
 
Shresthaal:

I've run into this several times, as my box is a VFP junky. The problem with creating an ODBC DSN is that when you deploy it, you have to create the DSN on the machine. This is one I use.

(It fills a dataset and then a grid, but you should be able to get the idea.)
=================================
Private Sub ConnectToData()

Try
'Ensure we know which database table we are using
If Opt1.Checked = True Then
DB = Opt1.Text
Else
DB = Opt2.Text
End If

'Create the connection string for the connection
Dim cS As String = "BackgroundFetch=Yes;Collate=Machine;" & _
"Exclusive=No;UID=;SourceType=DBF;Driver=Microsoft Visual FoxPro Driver;" & _
"SourceDB=Y:\INFOSYS\" & DB

'Add the connection
DBCon = New Odbc.OdbcConnection(cS)

'Add the Adapter
DBA = New Odbc.OdbcDataAdapter

'Open the connection
DBCon.Open()

'Declare the SQL String Task
Dim cmdTask As Odbc.OdbcCommand = _
New Odbc.OdbcCommand(txtSQL.Text, DBCon)
cmdTask.CommandType = CommandType.Text

DBA.SelectCommand = cmdTask

'create a dataset
DS = New DataSet("Tasks")

'fill the dataset
DBA.Fill(DS)

'Create a table for the adapter
DBA.TableMappings.Add("Table", "Tasks")

'close the connection
DBCon.Close()

'bind the data to the datagrid
Grid1.SetDataBinding(DS, "Table")
Catch ex As Exception
MessageBox.Show("Check your SQL statement.", "SQL Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try
End Sub
===============================
Option buttons contain the names of the database/table.

I hope this helps.

Ron

Ron Repp
 
I have tried this to, 1st without success - later I found that my problem was that the driver to open fp dbf was not up to date in .net 2003

make sure you download the latest fox 8 or fox 9 OLb Db for fox driver from microsoft!

Cam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top