954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

reading records from a .dbf file

anyone who can help me regarding how to read data from .dbf files recordwise.

suneel kar
Junior Poster in Training
71 posts since Jul 2007
Reputation Points: 10
Solved Threads: 1
 
anyone who can help me regarding how to read data from .dbf files recordwise.



See it in the threadAccess to any type of DB's possible for your dbase and opening 2 files for your writng records to text files


regards
AV Manoharan

AV Manoharan
Junior Poster
166 posts since Jun 2007
Reputation Points: 10
Solved Threads: 9
 

Hi Suneel,

Add DAO reference :Microsoft DAO 3.51 object Library To ur Project and use thos code:

Dim DB As Datbase
Dim RST As RecordSet
Dim sSQL As String
Set DB = DBEngine.OpenDatabase("C:\MyDBFFolder", False, False, "dBASE III;")
sSQL= "Select * From MyTable"
Set RST= DB.penRecordset(sSQL)


Note In Above DB Statement, u have to specify the path of Folder Name where Dbf files are Located. and u can change the
DBase III according to ur dbase version.

REgards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

hi veena ,
thanx for replyin. will u plz tell me what actually this statement does in code.
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\Resources\MNYL.mdb ; Persist Security Info=False"

As i am new to programming in visual basics so tell me any way to get every cocept clear.
any book if u recomend me .will be thankful.
dabasish and u have strong knowlge of vb .keep it up .
regards
suneel kar

Hi Suneel, Add DAO reference :Microsoft DAO 3.51 object Library To ur Project and use thos code:

Dim DB As Datbase
Dim RST As RecordSet
Dim sSQL As String
Set DB = DBEngine.OpenDatabase("C:\MyDBFFolder", False, False, "dBASE III;")
sSQL= "Select * From MyTable"
Set RST= DB.penRecordset(sSQL)

Note In Above DB Statement, u have to specify the path of Folder Name where Dbf files are Located. and u can change the DBase III according to ur dbase version. REgards Veena

suneel kar
Junior Poster in Training
71 posts since Jul 2007
Reputation Points: 10
Solved Threads: 1
 

hi veeva
i am gettin confused dear. as per debashish he is sayin ADO is advanced one which we r using now and u sayin DAO
sort out the things and reply which to use
regards
suneel kar

hi veena , thanx for replyin. will u plz tell me what actually this statement does in code. con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\Resources\MNYL.mdb ; Persist Security Info=False"

As i am new to programming in visual basics so tell me any way to get every cocept clear. any book if u recomend me .will be thankful. dabasish and u have strong knowlge of vb .keep it up . regards suneel kar

suneel kar
Junior Poster in Training
71 posts since Jul 2007
Reputation Points: 10
Solved Threads: 1
 

Hi vee!

Set db = OpenDatabase(App.Path & "\COLOR.dbf", False, False, "dBase IV;")

I try your code because I also use some dBase but it has an error "C:\report\Color.dbf" isn't a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.I don't understand why because the color.dbf file is in the folder c:\report and my VB Project is also on that folder too. Why it makes an error like that?

jireh
Posting Whiz
316 posts since Jul 2007
Reputation Points: 11
Solved Threads: 49
 

Hi Jireh,

Look as i said in my post u should mention only dbf's "Path"
change "C:\report\Color.dbf" this to
"C:\report"

DBF files donot have the concept of Single Databeas, each tables are stored as seperate
files, thats the reason we need to mention Folder path of dbf files.

Hi Suneel,
DBF is a older technology of databases. It may be possible to open dbf with ADO also, but I think they can be accessed fast using DAO's .

Regards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

hello debashish,veena
have alook n the code.when i am compiling this it is givin me unknown databse format.
regards
suneel


Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\CHECK_2045.dbf ; Persist Security Info=False"
rs.Open Text1.Text, con, adOpenForwardOnly, adLockOptimistic
Dim str As String
If Dir("c:\Suneel_Development\New Folder\record reading\data.txt") <> "" Then
Kill "c:\Suneel_Development\New Folder\data.txt"
End If
Open "c:\Suneel_Development\New Folder\DATA.TXT" For Append As #1
Do While rs.EOF = False
For i = 0 To rs.Fields.Count - 1
If i < rs.Fields.Count - 1 Then
str = str & IIf(IsNull(rs(i)), "null", rs(i)) & Chr(9)
Else
str = str & IIf(IsNull(rs(i)), "null", rs(i))
End If
Next
Print #1, str
rs.MoveNext
str = ""
Loop
Close #1
rs.Close
con.Close
End Sub

Hi Jireh, Look as i said in my post u should mention only dbf's "Path" change "C:\report\Color.dbf" this to "C:\report"

DBF files donot have the concept of Single Databeas, each tables are stored as seperate files, thats the reason we need to mention Folder path of dbf files. Hi Suneel, DBF is a older technology of databases. It may be possible to open dbf with ADO also, but I think they can be accessed fast using DAO's . Regards Veena

suneel kar
Junior Poster in Training
71 posts since Jul 2007
Reputation Points: 10
Solved Threads: 1
 

Hi Suneel,

if u r using ADO, then open Connection like this:

con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & ";Extended Properties=DBase IV"


u have to give Extended properties in connection string, and when it comes to .dbf or older Foxpro Versions of data, they dont have a single DB, u have to mention Folder path name.


Regards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

Hi Suneel,

What does ur Text1.Text contain...?
It shoud have either Table name (CHECK_2045) or a Select Query Statment (Select * From CHECK_2045)


Regards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

hi veena .
con.open statement worked.
"rs.Open Text1.Text, con, adOpenForwardOnly, adLockOptimistic"
what it does actually.reply
regards
suneel

Hi Suneel, if u r using ADO, then open Connection like this:

con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & ";Extended Properties=DBase IV"

u have to give Extended properties in connection string, and when it comes to .dbf or older Foxpro Versions of data, they dont have a single DB, u have to mention Folder path name. Regards Veena

suneel kar
Junior Poster in Training
71 posts since Jul 2007
Reputation Points: 10
Solved Threads: 1
 

hi veena
is it possible that text1.txt can contain CHECK_2045.pdf.
can i give the name of folder directly where CHECK_2045 is present.
CHECK_2045 is present in C:\Suneel_development\New Folder\record reading\CHECK_2045.pdf
may i write like this
"rs.Open CHECK_2045.pdf, con, adOpenForwardOnly, adLockOptimistic
it is giving object required error.
wt to do here
regards
suneel
Hi Suneel,

What does ur Text1.Text contain...?
It shoud have either Table name (CHECK_2045) or a Select Query Statment (Select * From CHECK_2045)


Regards
Veena

suneel kar
Junior Poster in Training
71 posts since Jul 2007
Reputation Points: 10
Solved Threads: 1
 

hi Suneel,

In the above Program, con is the Connection Object which allows u to connect to the Database. Since Database has many sets of tables, u will have to use RecordSet object to access data.

check this :
rs.Open "Select * from MyTable", con, adOpenForwardOnly, adLockOptimistic

here RS is the Recordset object which actuualy holds Table Data, this is opened thru Con object.
CHECK_2005 should be .dbf File and Is actually the Table and u r opening it thru recordset.

u cannot open PDF files with ADO in VB6


Regards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

hi veena
we cannot open PDF files with ADO in VB6.is it so.
i placed CHECK_2045.dbf In MyTable and tried ur cde buttttt it could not find the MyTable
if u dont mind may i send u my project.
reply soon

suneel kar
Junior Poster in Training
71 posts since Jul 2007
Reputation Points: 10
Solved Threads: 1
 

Hi,

Create Folder "MyDBF" in C
and place all dbfs's there in ("c:\MyDBF")
and use this code:

con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDBF; Extended Properties=DBase IV"
rs.Open "Select * from CHECK_2005", con, adOpenForwardOnly, adLockOptimistic


Yes, u can send me the project. I will modify and return back.


Regards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

hi i was waitin for ur reply but u went offline. hey how to send projct to u.may i have ur mail id where i can send it .
reply now
regards
suneel
Hi,

Create Folder "MyDBF" in C
and place all dbfs's there in ("c:\MyDBF")
and use this code:

con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDBF; Extended Properties=DBase IV"
rs.Open "Select * from CHECK_2005", con, adOpenForwardOnly, adLockOptimistic


Yes, u can send me the project. I will modify and return back.


Regards
Veena

suneel kar
Junior Poster in Training
71 posts since Jul 2007
Reputation Points: 10
Solved Threads: 1
 

Hi,

U can Zip and upload the proj here, or i have sent u pvt msg abt my email id

Regards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

ya i got ur pvt msg.
veena my gmail id is [email]suneelkashmiri@gmail.com[/email],rediff id is [email]kar_suneel022@rediffmail.com[/email]
add me there .
modify the project and send it in my gmail id .
with regards
suneel kar

Hi, U can Zip and upload the proj here, or i have sent u pvt msg abt my email id Regards Veena
suneel kar
Junior Poster in Training
71 posts since Jul 2007
Reputation Points: 10
Solved Threads: 1
 

hi veena
if possible give me ur gmail id i will be thankful to u.
regards
suneel kar

suneel kar
Junior Poster in Training
71 posts since Jul 2007
Reputation Points: 10
Solved Threads: 1
 

Hi Vee,

you know I'm confused, why we dont need to mention the dbf file but only their path?

the connection is now ok but there's still a problem on me here why I can't use it in a query? here's my code for that dbf.

Set db = OpenDatabase(App.Path & "\", False, False, "dBase IV;")
Set Data1.Recordset = db.OpenRecordset("select * from color where clrcode='" & Text1.Text & "'")

Is there something I should add in my query?
The error is in here

Set Data1.Recordset = db.OpenRecordset("select * from color where clrcode='" & Text1.Text & "'")
jireh
Posting Whiz
316 posts since Jul 2007
Reputation Points: 11
Solved Threads: 49
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You