Click here to Skip to main content
15,885,875 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In my application i am reading data from excel and storing in DataTable object
code is as below
C#
string excelFilePath = "D:\\sunny1.xls";
            string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelFilePath + ";Extended Properties=Excel 12.0;";
            OleDbConnection excelOledbConObj = new OleDbConnection();
            excelOledbConObj.ConnectionString = connectionString;
           
            DataTable excelDataTable = new DataTable();
            excelOledbConObj.Open(); 
OleDbCommand oledbCmdObj = new OleDbCommand();
            oledbCmdObj.Connection = excelOledbConObj;
            try
            {
                
                OleDbDataAdapter oldataAdapterObj = new OleDbDataAdapter(oledbCmdObj);
                oledbCmdObj.CommandText = "Select * from [" +sb1.ToString()+"]";

                oldataAdapterObj.Fill(excelDataTable);
            }
            catch (OleDbException ex)
            {
                Response.Write(ex.Message);
            }

and my excel data is as follows:-

EmpCode	Title<br />
999312	mr<br />
As9991  miss<br />
when i execute my application  my datatable have data as follows<br />
999312	mr<br />
NULL  miss<br />
why i am getting null value over here

can anyone help me out here. I believe its happen due the different type of data in my EmpCode column
Posted
Updated 6-May-11 2:02am
v2

1 solution

 
Share this answer
 
Comments
spydeehunk 6-May-11 8:28am    
thanks it helped me out much

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