Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB Databases
|
Pro VB Databases Advanced-level VB coding questions specific to using VB with databases. Beginning-level questions or issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 18th, 2005, 03:07 AM
Registered User
 
Join Date: Jan 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default ADO INSERT to CSV file I get mismatch error

Newbie using ADO vba Excel to connect to a csv text file. I keep getting a type mismatch on the third field. Somehow ADO considers it to be a number field inspite of the fact that several of the column entries are Number/Alpha combos (eg 3a 2b etc). Any suggestions on how I can I avoid the "Type Mismatch" Error? Is there a way to assign types to the fields before the insert?
My code basically uses the sample code from page 401 of WROX Programmers Ref Excel 2002 ... to perform an ADO INSERT on a csv text file.
The 3rd field (batid) should be considered a text field but the ‘aa1’ INSERT keeps generating a ‘type mismatch” error. It will only allow pure numbers.

Here’s the code
'=======================
   szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
    & "Data Source=" & stDB & ";" & _
                "Extended Properties=Text;"

    Set objCommand = New ADODB.Command
    objCommand.ActiveConnection = szConnect

    objCommand.CommandText = "INSERT INTO " & FileName & "(Insid, insdate,batid) " & _
    "VALUES('TestINS','1/1/2001','aa1');"

'=======================
Rene


Rene
 
Old January 18th, 2005, 05:56 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

u can use a schema.ini file to tell the text driver what all the fields are. see here for details:
http://msdn.microsoft.com/library/de...a_ini_file.asp
 
Old January 18th, 2005, 05:40 PM
Registered User
 
Join Date: Jan 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That WORKS!
Wow...Thanks, and so quick too!.
Was trying to find a sample of a schema.ini and found an easy way to make em by using the Administrative tools/Data Sources (ODBC)in the Control Panel.
First "Text Files" then "Configure".
Uncheck "Use Current Directory".
Click "Select Directory" to locate directory the source files are. Click "Options" "Define Format". In the "Define Text Format" dialog, Select each csv source file,
  Click Column Name Header (in my case)
   then Guess.
Finally click OK
then CANCEL.
A schema.ini file gets created in the source file directory.
I had to edit it to add "Char" after each char field. For some reason the process I just described, defines all the other fields but not the Char and this creates an error "The Col 1 option is invalid".
Thanks again.
Rene


Rene
 
Old January 19th, 2005, 06:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hey, nice tip about creating the schema.ini. Thanks.

Phil





Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Mismatch Error arholly SQL Server ASP 1 March 18th, 2008 02:34 AM
hi i got runtime error 13 Type Mismatch error sriharsha345 Access VBA 2 February 21st, 2008 09:30 AM
Mismatch error Sheraz Khan ASP.NET 2.0 Basics 3 May 16th, 2007 10:50 AM
DTS mismatch error venkatkk SQL Server DTS 1 July 28th, 2004 08:40 AM
Mismatch Error on OpenRecordset mikedu Access VBA 4 February 19th, 2004 11:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.