WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADO DAO
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Example Converts CSV file into an Access Database

Keywords:   csv2acc.wbt	  ADO - TAB-delimited to MDB conversion

Here is a script that uses a simple SELECT to insert a csv file into a table. This should also place an entry for the csv in the schema.ini file.

csv2acc.wbt

nVer      = 2000  ; for office 97, see nVer (below)
cMDB      = "C:\TEMP\NEWTBL.MDB"
If FileExist(cMDB) Then FileDelete( cMDB )


cPath     = "C:\TEMP"
cTXT      = "USERS.TXT"  ; first row has column names
If ! FileExist( Strcat( cPath,"\",cTXT ) )
   message("Unable to Continue","Missing Text File %cTXT%")
   Exit
Endif

; on with the show
BoxOpen("Updating %cMDB%","Inserting Records")
If nVer   == 97 ;create Office 97 compatible file
   cConn  = "Provider=MicroSoft.Jet.OLEDB.4.0; Data Source=%cMDB%;Jet OLEDB:Engine Type=4"
Else
   cConn  = "Provider=MicroSoft.Jet.OLEDB.4.0; Data Source=%cMDB%"
Endif

If ! FileExist( cMDB )
   cat    = ObjectOpen("ADOX.Catalog")
   cat.Create(cConn)
   ObjectClose(cat)
Endif

DB        = ObjectOpen("ADODB.Connection")
DB.Open(cConn)
cSQL   = 'SELECT * INTO [USERS] FROM [TEXT;DATABASE=%cPath%;HDR=YES;FMT=Delimited].[%cTXT%];'

DB.EXECUTE(cSQL)

;ok, so Table is Created
RS     = ObjectOpen("ADODB.Recordset")

cSQL   = 'SELECT USER, SUM(MINUTES) as TOTALMINUTES FROM USERS GROUP BY USER;'
RS     = DB.EXECUTE(cSQL)

RS.MoveFirst()
While ! RS.Eof()
   fld = RS.Fields("USER")
   n   = fld.Value
   fld = RS.Fields("TOTALMINUTES")
   m   = fld.Value
   Message( "User %n%","Had %m% Total Minutes" )
   RS.MoveNext()
EndWhile

RS.Close()
ObjectClose(RS)
DB.Close()
ObjectClose(DB)
BoxShut()
Exit

Article ID:   W15597
File Created: 2003:05:13:11:29:10
Last Updated: 2003:05:13:11:29:10