Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello
I Have A problem that im reading an Excel file using oledb and Convert that into DataTable so whenever i fetch data from Excel that replace Some Special characters with like 'Ó' replaces with '?' But i want that characters remains as it is

my Code for Reading Data from Excel file

C#
private DataSet getData(string Path)
        {
            string fileName = Path;
            string connectionString = @"Provider=Microsoft.ACE.OLEDB.14.0;Data Source="+fileName+";ExtendedProperties="+"Excel 12.0;HDR=YES;";
            OleDbConnection con = new System.Data.OleDb.OleDbConnection(connectionString);
            con.Open();
            OleDbDataAdapter cmd = new System.Data.OleDb.OleDbDataAdapter("select * from [SHEET1$]", con);
            DataSet excelDataSet = new DataSet();
            cmd.Fill(excelDataSet);
            
            con.Close();
            return  excelDataSet;
        }


------------------------------
*Input -> RamÓn y Cajal,

*Actual Output -> Ram?n y Cajal,

*Expected Output -> RamÓn y Cajal,



I think its because of Character encoding Format .
Please help me
C#

Posted

1 solution

plz try this connection string
C#
strExcelCon = @"Provider=Microsoft.ACE.OLEDB.14.0;Data Source=" + sExcelPath + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'";
 
Share this answer
 
v2

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