borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Call Display for recordset data not working)Next Topic (URL  related question ??) New Topic New Poll Post Reply
AndreaVB Forum : Database : Disconnected recordset to Access database
Poster Message
crisem
Level: Guest


icon Disconnected recordset to Access database

Is there a way that i can put back into an access database, my saved disconnected recordset text file?

14-09-2002 at 06:45 PM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: Disconnected recordset to Access database

You can import data from a text file (and numerous other types).

In AccessXP it's in the menu:
   File/Get External Data/Import

If you right click in an empty space where the database's tables are displayed, you can select import.

14-09-2002 at 09:18 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
crisem
Level: Guest

icon Re: Re: Disconnected recordset to Access database

Thanks but i want to do it programmatically using vb6 'coz i'm a bit confused on how to do it using ado.


quote:
JLRodgers wrote:
You can import data from a text file (and numerous other types).

In AccessXP it's in the menu:
   File/Get External Data/Import

If you right click in an empty space where the database's tables are displayed, you can select import.


16-09-2002 at 12:02 AM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: Disconnected recordset to Access database

Since Access doesn't have a BULK INSERT command (at least that I've seen in the help file), the following should do it (with a few modificatoins):


Private Sub DBImport()
    On Error GoTo Err_DBImport
    Dim adc As New ADODB.Connection
    Dim ars As New ADODB.Recordset
    Dim iFree As Integer
    Dim cd() As String
    Dim tmp As String
    Dim i As Integer
    
' Open data file
    iFree = FreeFile
    Open "filename.txt" For Input As iFree ' the filename to input
    
' Open Database
    adc.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1;Persist Security Info=False"

' Get first line for column names
    Line Input #iFree, tmp
    cd() = Split(tmp, ",") ' assuming , is the dividing char
' Set SQL start
    tmp = "CREATE TABLE [ImportData]("
    
' Set col names based on first row
    For i = LBound(cd()) To UBound(cd()) - 1
        tmp = tmp & "[" & cd(i) & "] TEXT(50) , "
    Next
' Set last row
    tmp = tmp & "[" & cd(UBound(cd())) & "] TEXT(50))"
' Create the table
    adc.Execute tmp
' Open the table
    ars.Open "[ImportData]", adc, adOpenDynamic, adLockOptimistic
' Insert the remaining data
    Do
        Line Input #iFree, tmp
        cd() = Split(tmp, ",")
        ars.AddNew
        For i = LBound(cd()) To UBound(cd())
            ars.Fields(i) = cd(i)
        Next
        ars.Update
    Loop Until EOF(iFree)
    
' CLose the file
    Close
' Close the db
    ars.Close
    adc.Close
' Clear the vars
    Set ars = Nothing
    Set adc = Nothing
    
Err_DBImport:
    MsgBox Err.Description
    Set adc = Nothing
    Set ars = Nothing
    Close
End Sub

16-09-2002 at 03:05 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
crisem
Level: Guest

icon Re: Re: Disconnected recordset to Access database

Thanks

16-09-2002 at 05:23 AM
| Quote Reply
AndreaVB Forum : Database : Disconnected recordset to Access database
Previous Topic (Call Display for recordset data not working)Next Topic (URL  related question ??) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder