日期:2014-05-18  浏览次数:20991 次

技术求助!!急急急急急!!!
C# code
public DataTable GetExcelConnect(string p_dataPath,string p_Filename)
        {
            try
            {
                string path = @"E:\Documents and Settings\Administrator\桌面\DQUOT20120224\DQUOT\bin\Debug\";
                string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Text;HDR=Yes;FMT=Delimited\"";

                OleDbConnection myConnect = new OleDbConnection(strCon);
                if (myConnect.State == ConnectionState.Closed)
                {
                    myConnect.Open();
                }
                string strCommand = "select * from 17.txt";

                OleDbDataAdapter myCommand = new OleDbDataAdapter(strCommand, myConnect);
                DataSet myDataSet = new DataSet();
                DataTable dataTable = new DataTable();
                myCommand.Fill(dataTable);
                if (myConnect.State == ConnectionState.Open)
                {
                    myConnect.Close();
                }

                return dataTable;
            }
            catch (Exception ex)
            {
                return null;
            }
        }


17.txt内容格式:1,2,3,4,5,00001
  2,2,8,9,5,aaa

问题:将txt内容放入datatable中后,00001就只能读到1了,前面的0没有了(txt打开是完整的)。怎么处理。各位大侠。



------解决方案--------------------
探讨

当做整数读了,text结构不严谨,无法区分数字和文本,建议用文件流的形式读取,

------解决方案--------------------
txt文件干吗用 OleDbConnection
直接文件流读取
FileStream fs = new FileStream(url, FileMode.Open);
StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default);
//记得释放资源。