|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to write into text file from Access Database
Hello,
Can someone give me example on how to write the data from Access into a text file. thanks in advance. |
|
#2
|
|||
|
|||
|
read access data and write it into a text file with some data struct??This is a simple class used to export access databases to text files using DAO, along with an application that uses the class. You can specify which table to export and the number of fields, though as written, you can't specify which fields to include or exclude.
http://www.freevbcode.com/code/expdb.zip |
|
#3
|
||||
|
||||
|
Use the RecordSet's 'GetString' method.
It is of the form: recordset.GetString(StringFormat, NumRows, ColumnDelimiter, RowDelimiter, NullExpr) Follow the link below fo rmore info... MSDN Library RecordSet.GetString page |
|
#4
|
|||
|
|||
|
MSDN sample:
Code:
'BeginGetStringVB
'To integrate this code
'replace the data source and initial catalog values
'in the connection string
Public Sub Main()
On Error GoTo ErrorHandler
' connection variables
Dim Cnxn As ADODB.Connection
Dim rstAuthors As ADODB.Recordset
Dim strCnxn As String
Dim strSQLAuthors As String
Dim varOutput As Variant
' specific variables
Dim strPrompt As String
Dim strState As String
' open connection
Set Cnxn = New ADODB.Connection
strCnxn = "Provider='sqloledb';Data Source='MySqlServer';" & _
"Initial Catalog='Pubs';Integrated Security='SSPI';"
Cnxn.Open strCnxn
' get user input
strPrompt = "Enter a state (CA, IN, KS, MD, MI, OR, TN, UT): "
strState = Trim(InputBox(strPrompt, "GetString Example"))
' open recordset
Set rstAuthors = New ADODB.Recordset
strSQLAuthors = "SELECT au_fname, au_lname, address, city FROM Authors " & _
"WHERE state = '" & strState & "'"
rstAuthors.Open strSQLAuthors, Cnxn, adOpenStatic, adLockReadOnly, adCmdText
If Not rstAuthors.EOF Then
' Use all defaults: get all rows, TAB as column delimiter,
' CARRIAGE RETURN as row delimiter, EMPTY-string as null delimiter
varOutput = rstAuthors.GetString(adClipString)
' print output
Debug.Print "State = '" & strState & "'"
Debug.Print "Name Address City" & vbCr
Debug.Print varOutput
Else
Debug.Print "No rows found for state = '" & strState & "'" & vbCr
End If
' clean up
rstAuthors.Close
Cnxn.Close
Set rstAuthors = Nothing
Set Cnxn = Nothing
Exit Sub
ErrorHandler:
' clean up
If Not rstAuthors Is Nothing Then
If rstAuthors.State = adStateOpen Then rstAuthors.Close
End If
Set rstAuthors = Nothing
If Not Cnxn Is Nothing Then
If Cnxn.State = adStateOpen Then Cnxn.Close
End If
Set Cnxn = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
'EndGetStringVB
Last edited by Onslaught : October 11th, 2003 at 01:26 PM. |
|
#5
|
|||
|
|||
|
will it be similar if i use a oracle db?
|
|
#6
|
|||
|
|||
|
puteri_84,if u use oracle,U should modify this connect statement in above my program:
strCnxn = "Provider='sqloledb';Data Source='MySqlServer';" & _ "Initial Catalog='Pubs';Integrated Security='SSPI';" Cnxn.Open strCnxn ==>strCnxn = "Provider=MSDAORA.1;Database=table1; User id=user;Password=***;" Cnxn.Open strCnxn ... |
|
#7
|
|||
|
|||
|
I tried it..but then when i run the form nothing come out. Can you pls tell me step by step instruction of what i should do because i am very new to programming. Thanks a lot..
|
|
#8
|
|||
|
|||
|
OK!
What is VB and what is it used for? Visual Basic (VB) is an extremely popular and easy to use programming language provided by Microsoft Corporation. VB is mainly used to develop Windows based applications with. What is DAO, RDO and OLE DB? Which one should one use? DAO, RDO, ADO and OLE DB are data access methods that all accomplish exactly the same task. DAO - Data Access Objects (1-tier) Allow VB applications to talk to a database (the JET Engine) via ODBC. DAO was Microsoft's first object oriented solution for the manipulation of databases using the Jet Database Engine. The JET engine duplicates the functionalities of ODBC, and thus does not add much value. As the JET engine is generic, many of Oracle's features would not be accessible. Microsoft is currently phasing out this method. RDO - Remote Data Objects (2-tier) Allow VB applications to talk to a relational database (various Relational DBMSs) via ODBC. RDO is an interface to remote RDBMS via OBDC. One needs the Enterprise Edition of Visual Basic to use RDO. Microsoft is encouraging developers to migrate their RDO programs to ADO and OLE-DB. ADO - ActiveX Data Objects (1 to n-tier) Allow VB/Other Web Tools (Browsers) to interface with different kinds of data sources. ADO is a more recent Microsoft Data Access technology designed to replace DAO and RDO. ADO is designed to be simpler to use and more powerful than DAO/RDO. Serves an interface to Microsoft's new OLE-DB technology (thinner than ODBC). Can be used to access all sorts of "non traditional data" (e.g., web pages/documents, etc.). OLE DB data provider OLE DB is Microsoft's successor to ODBC that utilizes a set of COM interfaces for accessing and manipulating of data. Oracle implemented OLE DB as part of their "Oracle Provider for OLE DB" client software. It provides interface for both data-consuming applications and database providers. OLE DB is considered a thin middle layer which provides better data access performance. Summary RDO and DAO still works in VB for backwards compatibility. However, it is best to convert to ADO or OLE-DB. How does one connect to Oracle from VB? Connectivity to Oracle is provided via ODBC or OO4O (Oracle Objects for OLE). For more information about ODBC, read the ODBC FAQ. For information about OO4O, read the OO4O FAQ. Look at this examples: ' DAO Example (Data Access Objects) Dim wstemp As Workspace Dim dbtemp As Database Dim rstemp As Recordset Set wstemp = DBEngine.Workspaces(0) Set dbtemp = wstemp.OpenDatabase("", False, False, "ODBC;DSN=Oracle;USR=scott;PWD=tiger") Set rstemp = dbtemp.OpenRecordset(myquery.Text, dbOpenDynaset, dbSQLPassThrough) howmany = 0 Combo1.Clear Do Until rstemp.EOF msgbox rstemp(0) rstemp.MoveNext howmany = howmany + 1 Loop ' DAO Example (Data Access Objects) Dim contemp As New rdoConnection Dim rstemp As rdoResultset Dim envtemp As rdoEnvironment Set envtemp = rdoEngine.rdoEnvironments(0) envtemp.CursorDriver = rdUseServer ' or rdUseOdbc, rdUseNone, rdUseIfNeeded, rdUseClientBatch With contemp .Connect = "ODBC;DSN=Oracle;USR=scott;PWD=tiger" .EstablishConnection rdDriverNoPrompt, false, rdoForwardOnly ' or rdoStatic, rdoKeyset, rdoDynamic End With Set rstemp = contemp.OpenResultset("select ...") ' Your SQL here End If howmany = 0 With rstemp Do Until .EOF Or howmany > 2000 msgbox .rdoColumns(0) ' Give a message box of the 1st column .MoveNext howmany = howmany + 1 Loop ADO Example dim conn as ADODB.Connection dim rs as recordset Conn.Open "...", "...", "..." ' ^DSN ^User ^Password Set RS = Conn.Execute( "SELECT * FROM theTable" ) do while not rs.eof msgbox RS(i).Value rs.movenext loop Set RDODatabase = rdoEnvironments(0).OpenConnection("", rdDriverNoPrompt, True, "") Set RDOResultSet = RDODatabase.OpenResultset(SqlString.Text) TxtNumRows.Text = RDOResultSet.RowCount Why is there only one record in my recordset? When you do a recordcount and it return only one record in the recordset, while you know there are more records, you need to move to the last record before doing the count. Look at this example. Dim rs As Recordset rs.MoveLast TxtNumRows.Text = rs.RecordCount NOTE: Don't forget to do a rs.MoveFirst to get back to the first record again. All above at the site:http://www.orafaq.org/faqmsvb.htm |
|
#9
|
||||
|
||||
|
Wow, Pig... you sure are clever!
__________________
Fisherman "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > How to write into text file from Access Database |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|