Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

When I display my CSV file into my DataGridView some of the cells in the first row are blank.

Posted on 2009-04-09
8
Medium Priority
?
388 Views
Last Modified: 2013-12-17
I am displaying the contents of a CSV file into a DataGridView using an OleDbAdapter. The problem is once the data is in the DataGridView, some of the cells in the first row(which is the column headers in the CSV file) are blank. I have noticed the cells that are blank, are the header text for a column that contain numbers. I have tried placing quotes around the numbers in the CSV file and around the column headers but that has not helped. I am using cs.net 2008. In the code, fileName is a variable that is set before the TryCatch. All the data with the exception of row one is displaying correctly. Any help will be greatly appreciated.
OleDbConnection myConn = new OleDbConnection(connString);
            try
            {
                myConn.Open();
                DataTable dTable = new DataTable();
                OleDbDataAdapter myDa = new OleDbDataAdapter("SELECT * FROM[" + fileName + "]", myConn);
                myDa.Fill(dTable);
                myConn.Close();
                this.dataGridView_MonitorResults.DataSource = dTable;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

Open in new window

0
Comment
Question by:rsgage
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 14

Expert Comment

by:jjardine
ID: 24110864
can you give us the header row from the csv?   Try putting [] around the header.
0
 

Author Comment

by:rsgage
ID: 24110944
Yes here is the information from the header row.
store_nbr, country_code,thin_client_name,firmware_version_code,hardware_type_code,os_version_code,mac_address_id,ip_address_id, serial_nbr, online_ind, last_reimage_ts, last_change_ts, up_time_duration_ts, purchase_date, manufacture_date, end_of_life_date, screen_resolution_txt, refresh_rate_htz_qty, touch_scrn_calib_txt, ntwk_speed_mb_qty, disk_space_byte_qty, memory_byte_qty,

I will try the [] and will let you know.
0
 

Author Comment

by:rsgage
ID: 24110987
I tried putting in the [] and that did not help.
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 64

Expert Comment

by:Fernando Soto
ID: 24111686
Hi rsgage;

Can you post a sample file that causes the problem. I have used this before without that type of a issue.

Fernando
0
 

Author Comment

by:rsgage
ID: 24111842
Here is a sample. Normally it is named .csv but I coud not upload that type of file. The contents are the same though.
0001-monitor-test.txt
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 24112604
Hi rsgage;

I used your code and your test file that you posted and all column headers were displayed in the DataGridView. The only thing I can think of is that we are using different connection strings, this is the one I used:

string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\Temp\;Extended Properties=""text;HDR=Yes;FMT=Delimited""";

Note that in the connection string d:\Temp\ is the directory that the CSV file is located in.

Fernando
0
 

Author Comment

by:rsgage
ID: 24129624
Fernando, changing the connection string worked perfectly. Thank you so much.
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 24132159
Not a problem, glad I was able to help.  ;=)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question