Click here to Skip to main content
15,903,385 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I want to read excel file from C# and fill the data to a DataTable. I have written the code as below.

C#
string strNewPath = Server.MapPath("~/UploadExcel/" + "Action Center_Agent.xls");
 string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strNewPath + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
        // Create the connection object

        OleDbConnection oledbConn = new OleDbConnection(connString);
        try
        {
            oledbConn.Open();
            OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Agent$A9:Z500]", oledbConn);
            OleDbDataAdapter oleda = new OleDbDataAdapter();
            oleda.SelectCommand = cmd;
            DataSet ds = new DataSet();
            oleda.Fill(ds, "Customer");
            DataTable dtExcel = new DataTable();
            dtExcel = ds.Tables[0];
         }
        catch
        {
        }
        finally
        {
           
            oledbConn.Close();
        }

Everything is working fine. But the problem is that the excel sheet contains a column which contains 80 characters. It is not able to read all the charactes of that colums.It is reading 60 characters and remaining characters are getting skipped . So can u please help me how to read complete column name please ?
Posted
Updated 23-Sep-12 6:18am
v2

1 solution

 
Share this answer
 

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