Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / November 2006



Tip: Looking for answers? Try searching our database.

Two CSV files, same format, same function, different results

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
clint.hudson@gmail.com - 23 Nov 2006 06:11 GMT
I'm writing a program in VB to do some engineering analysis.  I have
two text files with nearly the same format, same columns and data
types, but different data.  For the sake of argument, let's call one of
the files A.csv and the other B.csv.

I have two different functions set up to read each of the files because
the data gathered will be used in two different ways.  However, in each
of these functions, the ADODB commands are almost exactly alike.  When
I run one of the functions, invoked when a combobox receives focus,
everything works great.  When I run the other, invoked when a different
combo box receives focus, I get an error to the effect of
"[Microsoft][ODBC Text Driver] Too few parameters. Expected 1."

Snippet of Function 1, for A.csv:
  connCSV.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" _
  & sPath & ";Extensions=asc,csv,tab,txt;HDR=NO;Persist Security
Info=False"

  sSource = "Select Size, Capacity, Width"
  sSource = sSource & " From " & sFileName & ".csv"
  sSource = sSource & " Where Units = '" & sUnit & "'"
  sSource = sSource & " and Size <= " & dDiameter

  rsTest.Source = sSource

  rsTest.Open , connCSV, adOpenStatic, adLockReadOnly, adCmdText

Snippet of Function 2, for B.csv:
  connCSV.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" _
  & sPath & ";Extensions=asc,csv,tab,txt;HDR=NO;Persist Security
Info=False"

  sSource = "Select Size, Capacity, Width"
  sSource = sSource & " From " & sFileName & ".csv"
  sSource = sSource & " Where Units = '" & sUnit & "'"
  sSource = sSource & " and Size > " & dDiameter

  rsTest.Source = sSource

  rsTest.Open , connCSV, adOpenStatic, adLockReadOnly, adCmdText

Can anyone see what the difference is?  Similar oddities have happened
to me on this project which leads me to believe that either ADO's are
temperamental little monsters, and/or I simply have no idea what I'm
doing.

I've verified that sPath, sUnit, sFileName, and sDiameter are set
correctly, and that the sSource string looks like it should.  The two
examples of the source string are included below:
Example 1:
Select Size, Capacity, Width From A.csv Where Units = 'I' and Size <=
4.9375

Example 2:
Select Size, Capacity, Width From B.csv Where Units = 'I' and Size >
5.1875

Thanks!
Paul Clement - 28 Nov 2006 15:38 GMT
¤ I'm writing a program in VB to do some engineering analysis.  I have
¤ two text files with nearly the same format, same columns and data
¤ types, but different data.  For the sake of argument, let's call one of
¤ the files A.csv and the other B.csv.
¤
¤ I have two different functions set up to read each of the files because
¤ the data gathered will be used in two different ways.  However, in each
¤ of these functions, the ADODB commands are almost exactly alike.  When
¤ I run one of the functions, invoked when a combobox receives focus,
¤ everything works great.  When I run the other, invoked when a different
¤ combo box receives focus, I get an error to the effect of
¤ "[Microsoft][ODBC Text Driver] Too few parameters. Expected 1."
¤
¤ Snippet of Function 1, for A.csv:
¤    connCSV.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" _
¤    & sPath & ";Extensions=asc,csv,tab,txt;HDR=NO;Persist Security
¤ Info=False"
¤
¤    sSource = "Select Size, Capacity, Width"
¤    sSource = sSource & " From " & sFileName & ".csv"
¤    sSource = sSource & " Where Units = '" & sUnit & "'"
¤    sSource = sSource & " and Size <= " & dDiameter
¤
¤    rsTest.Source = sSource
¤
¤    rsTest.Open , connCSV, adOpenStatic, adLockReadOnly, adCmdText
¤
¤ Snippet of Function 2, for B.csv:
¤    connCSV.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" _
¤    & sPath & ";Extensions=asc,csv,tab,txt;HDR=NO;Persist Security
¤ Info=False"
¤
¤    sSource = "Select Size, Capacity, Width"
¤    sSource = sSource & " From " & sFileName & ".csv"
¤    sSource = sSource & " Where Units = '" & sUnit & "'"
¤    sSource = sSource & " and Size > " & dDiameter
¤
¤    rsTest.Source = sSource
¤
¤    rsTest.Open , connCSV, adOpenStatic, adLockReadOnly, adCmdText
¤
¤ Can anyone see what the difference is?  Similar oddities have happened
¤ to me on this project which leads me to believe that either ADO's are
¤ temperamental little monsters, and/or I simply have no idea what I'm
¤ doing.
¤
¤ I've verified that sPath, sUnit, sFileName, and sDiameter are set
¤ correctly, and that the sSource string looks like it should.  The two
¤ examples of the source string are included below:
¤ Example 1:
¤ Select Size, Capacity, Width From A.csv Where Units = 'I' and Size <=
¤ 4.9375
¤
¤ Example 2:
¤ Select Size, Capacity, Width From B.csv Where Units = 'I' and Size >
¤ 5.1875

I see a couple of issues here. First, you're using column names but the HDR argument is set to NO. I
can't see how the column names would be recognized in this instance. The second issue is the use of
the column name Size. This is a reserved word in Jet so you either need to enclose it in brackets or
rename it.


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.