Results 1 to 7 of 7

Thread: [RESOLVED] [2005] Error with CSV files

  1. #1

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407

    Resolved [RESOLVED] [2005] Error with CSV files

    I have a program that runs a WMI query and writes the data to a temp CSV file then imports that data into a datagrid so the user is able to view the data. When I have this data in the temp file like this:

    Code:
    Server Disk Configuration for myServer
    
    Caption, ConfigManagerErrorCode, Description, DeviceID, DriveType, ErrorDescription, Filesystem, MediaType, Name, TotalCapacity, Status, FreeSpace
    It displays in the datagridview perfectly fine.... but when I have this temp CSV file displayed in the grid:

    Code:
    Server Disk Configuration for myServer
    
    Caption, ConfigManagerErrorCode, Description, DeviceID, DriveType, ErrorDescription, Filesystem, MediaType, Name, TotalCapacity, Status, FreeSpace
    
    C:,,Local Fixed Disk,C:,3,,NTFS,12,C:,45,,28
    D:,,Local Fixed Disk,D:,3,,NTFS,12,D:,30,,25
    E:,,CD-ROM Disc,E:,5,,,11,E:0 GB,,0 GB,
    M:,,Network Connection,M:,4,,MVFS,0,M:,78,,49
    X:,,Network Connection,X:,4,,NTFS,0,X:,1641,,230
    Y:,,Network Connection,Y:,4,,NTFS,0,Y:,678,,59
    Z:,,Network Connection,Z:,4,,MVFS,0,Z:,78,,49
    It doesn't display properly in the grid view. It displays like the image below. What could be wrong? I am just loading the CSV file though an OleDb connection like this:

    vb Code:
    1. Dim objConn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & ";Extended Properties=""Text;HDR=No;FMT=Delimited""")
    2.             Dim objDataAdapter As New OleDb.OleDbDataAdapter()
    3.             Dim objDataSet As New DataSet
    4.             Dim objCommand As New OleDb.OleDbCommand("SELECT * FROM tmp_output.csv", objConn)
    5.  
    6.             objConn.Open()
    7.             objDataAdapter.SelectCommand = objCommand
    8.             objDataSet.Clear()
    9.             objDataAdapter.Fill(objDataSet, "CSV")
    10.             DataGridView.DataSource = objDataSet.Tables(0)
    11.  
    12.             For intColumnIndex As Integer = 0 To DataGridView.Columns.Count - 1
    13.                 DataGridView.Columns(intColumnIndex).SortMode = DataGridViewColumnSortMode.NotSortable
    14.             Next
    15.  
    16.             objConn.Close()
    17.  
    18.             tsProgressBar.Value = 95
    19.  
    20.             IO.File.Delete(Application.StartupPath & "\tmp_output.csv")
    21.             tsProgressBar.Value = 100
    22.  
    23.             tsProgressBar.Value = 0
    Attached Images Attached Images  

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2005] Error with CSV files

    Actually....it is correct... it's the Description text that's throwing it off.... it contains a comma.... Local Disk, C: .... when writing out a CSV, the C is COMMA... so if any of your text happens to contain a comma, you need to enclose the text in quotes....

    It should look like this:
    Code:
    C:,,"Local Fixed Disk,C:",3,,NTFS,12,C:,45,,28
    D:,,"Local Fixed Disk,D:",3,,NTFS,12,D:,30,,25
    E:,,"CD-ROM Disc,E:",5,,,11,E:0 GB,,0 GB,
    You'll see how the descriptions are enclosed in quotes... that should keep that text together.....

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Ancient City, U.S.
    Posts
    1,254

    Re: [2005] Error with CSV files

    I think I'm stoned. I don't see anything wrong with the grid except a few of the columns don't have headers. Otherwise the data looks lined up to me.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] Error with CSV files

    1. Do not write this header line "Server Disk Configuration for myServer" to your csv file.
    2. Set HDR=Yes in your connection string.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2005] Error with CSV files

    Starting with deviceID, the cols are off.... Device ID is a Number value... the C: that's jsut before the first Device ID is the ,C: from the description....

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Ancient City, U.S.
    Posts
    1,254

    Re: [2005] Error with CSV files

    The filesystem column looks like it has the right values. But hey, the ultimate judge is the thread starter. If he says it's not right, then it ain't right.

    Hey SomethinCool, has this been resolved?
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  7. #7

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407

    Re: [2005] Error with CSV files

    Yep, sorry. I haven't been on in a while. All I needed to do was put quotes around everything.. I think the C: was messing it all up.

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width