1 Attachment(s)
[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:
Dim objConn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & ";Extended Properties=""Text;HDR=No;FMT=Delimited""")
Dim objDataAdapter As New OleDb.OleDbDataAdapter()
Dim objDataSet As New DataSet
Dim objCommand As New OleDb.OleDbCommand("SELECT * FROM tmp_output.csv", objConn)
objConn.Open()
objDataAdapter.SelectCommand = objCommand
objDataSet.Clear()
objDataAdapter.Fill(objDataSet, "CSV")
DataGridView.DataSource = objDataSet.Tables(0)
For intColumnIndex As Integer = 0 To DataGridView.Columns.Count - 1
DataGridView.Columns(intColumnIndex).SortMode = DataGridViewColumnSortMode.NotSortable
Next
objConn.Close()
tsProgressBar.Value = 95
IO.File.Delete(Application.StartupPath & "\tmp_output.csv")
tsProgressBar.Value = 100
tsProgressBar.Value = 0
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
Re: [2005] Error with CSV files
I think I'm stoned. :confused: 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.
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.
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
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. :D
Hey SomethinCool, has this been resolved?
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!