Import Txt files into an ADP

  • Thread starter Thread starter Armando Vargas
  • Start date Start date
A

Armando Vargas

Hello!

Anyone has the solution into how to import text files into a ADP using code?
I found something, but dont know how it works.

Thanks!


Private Sub Comando0_Click()
LeerDelimitado ("c:\casetas.txt")
End Sub


Public Sub LeerDelimitado(sArchivo As String)
'Requiere referencia a Microsoft Scripting Runtime
Dim MiFSO As FileSystemObject, MiSTR As TextStream
'Referencia a objetos ADO
Dim cnn As ADODB.Connection, rs As ADODB.Recordset, i As Integer
Set cnn = New ADODB.Connection
'Configura tu cadena de conexión. Mira en http://tinyurl.com/n42r9
cnn.Open "Provider=sqloledb;" & _
"Server=MOBILxe;" & _
"Database=AdveXE;" & _
"User Id=sa;" & _
"Password=miserver"
Set rs = New ADODB.Recordset
rs.Open "TblRegistroIAVE", cnn, adOpenStatic, adLockOptimistic

Dim sCampos() As String
Set MiFSO = New FileSystemObject
Set MiSTR = MiFSO.OpenTextFile(sArchivo, ForReading)
Do Until MiSTR.AtEndOfStream
sCampos = Split(MiSTR.ReadLine, "|")
'Código para tratar la matriz sCampos
rs.AddNew
For i = LBound(sCampos) To UBound(sCampos)
rs.Fields(0) = sCampos(i)
Next
rs.Update
Loop
rs.Close
Set rs = Nothing
cnn.Close
Set cnn = Nothing
MiSTR.Close
Set MiSTR = Nothing
Set MiFSO = Nothing
End Sub
 
you should look up 'bulk insert'

in SQL Server books online.

it is a lot more powerful; and a lot faster.

i reccomend spending a couple of days; getting the hang of it.. you'll
never look back
 
Thanks!!

I finaly found the way, I used the DTS wizard, and Save it as VB Code, and
then run it.

Sorrry, it was my first time.

Armando!
<[email protected]> escribió en el mensaje


you should look up 'bulk insert'

in SQL Server books online.

it is a lot more powerful; and a lot faster.

i reccomend spending a couple of days; getting the hang of it.. you'll
never look back
 
Back
Top