Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends , being working for ages to get it resolve.

i have a Requirement where i need to import CSV (Tab delimited) file to SQL Server , all the code is working correctly and the data is getting imported correctly except the chinese characters .

The programming logic is to create the scheme.ini file as below

FileStream fsOutput = new FileStream(dirtrectoryinfo + "\\schema.ini", FileMode.Create, FileAccess.Write);
           StreamWriter srOutput = new StreamWriter(fsOutput, System.Text.Encoding.GetEncoding(936));

           string s1, s2, s3, s4, s5;

           s1 = "[" + fname + "]";
           s2 = "ColNameHeader=True";
           s3 = "Format=Delimited(|)";
           s4 = "MaxScanRows=25";
           s5 = "CharacterSet=ANSI";

           srOutput.WriteLine(s1.ToString() + "\r\n" + s2.ToString() + "\r\n" + s3.ToString() + "\r\n" + s4.ToString() + "\r\n" + s5.ToString());
           srOutput.Close();
           fsOutput.Close();


i used Unicode , but it hangs when the code reach at executeReader , if i use ANSI then the file get process but chinese character are not displayed correctly.

string sql_select;
               OdbcConnection conn;
               conn = new OdbcConnection(strConnString.Trim());
               conn.Open();
               OdbcCommand commandRowCount = new OdbcCommand("SELECT COUNT(*) FROM [" + fileName.Trim() + "]", conn);
               sql_select = "select * from [" + fileName.Trim() + "]";

               OdbcCommand commandSourceData = new OdbcCommand(sql_select, conn);
               commandSourceData.CommandTimeout = 0;
               OdbcDataReader dataReader = commandSourceData.ExecuteReader();
               DataTable dt;



whats is the correct way to create the schema.ini file and how can i import the file with correct chinese chracter
Posted
Comments
Richard MacCutchan 24-Jul-15 8:37am    
I don't think that CharacterSet=ANSI will read Chinese characters correctly.
Rickin Kane 24-Jul-15 9:40am    
i know thats y i use unicode in chracter but when i use unicode , the my batch job hangs at OdbcDataReader dataReader = commandSourceData.ExecuteReader();

so not sure where i am going wrong
Richard MacCutchan 24-Jul-15 11:36am    
I am not sure about using the ODBC class for reading Excel, I have always used OLEDB as described in http://www.codeproject.com/Articles/37055/Working-with-MS-Excel-xls-xlsx-Using-MDAC-and-Oled.
sreeyush sudhakaran 9-Aug-15 6:45am    
Better to use a stored procedure and pass your variables as arguments , Your database will automatically handle it.

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