Click here to Skip to main content
15,037,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

I have one excel file that first coloum have numeric and text data, when i am importing that data into datagridview, it would shows only numeric data and all text data rows is destroyed.

kindly send me a code for it.

C#
string connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""", filepath.Text);
string query = "select * from ["+cmbsheet.Text.Trim()+"$]";
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);
dataGridView1.DataSource = dataSet.Tables[0];



Excel File Data Are as under :

Coloum 1
1st row 1250
2nd row 1530
3rd row raj1122123
Posted
Updated 22-Jul-12 2:14am
v2

1 solution

I think your problem is answered here:

http://social.msdn.microsoft.com/forums/en-us/winformsdatacontrols/thread/20ABA57B-0111-4086-812A-DFE9792A96C4[^]

It says
"Change the cell format to Text in the excel file would fix this problem, if you stick to the General type or Numeric type of the cell, you have to read the excel file content into the DataTable manually."
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900