关键代码如下string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Text;HDR=Yes;FMT=Delimited\"";
OleDbConnection con = new OleDbConnection(conStr);//连接读取txt驱动
OleDbDataAdapter oda = null;//适配器
DataTable tblDatas = new DataTable();//存储的dt
string sql="select 时间 ,Value1 from 20110826.txt where 时间>=#2011-08-26 09:44:20# and 时间<=#2011-08-26 09:46:20#"
oda = new OleDbDataAdapter(strsql, con);
oda.Fill(tblDatas);txt中的内容
时间,Value1,....
2011-08-26 09:44:20,0.606,......读取时截取了小数位后面的数
输出的是"0"在写的时候用的是 Encoding.Default
请问这件事情如何解决和避免
谢.

解决方案 »

  1.   

    将数据存入txt文件中if (File.Exists("../../test.txt"))
                {
                    if (!this.txtZhangHao.AutoCompleteCustomSource.Contains(txtZhangHao.Text))//判断记录是否存在
                    {
                        StreamWriter sw = new StreamWriter("../../test.txt", false);//true参数不可少,否则会覆盖以前存入的记录
                        sw.WriteLine(this.txtZhangHao.Text.Trim());//存入记录
                        sw.Close();
                        if (!this.txtZhangHao.AutoCompleteCustomSource.Contains(this.txtZhangHao.Text))
                        {
                            this.txtZhangHao.AutoCompleteCustomSource.Add(this.txtZhangHao.Text);
                        }
                    }
                    this.DialogResult = DialogResult.OK;
                } 
    读取txt文件if (File.Exists(@"../../test.txt"))//路径和文件类型大家自己设置
                {
                    StreamReader sr = new StreamReader(@"../../test.txt", true);                string str = sr.ReadLine();
                    if (str != null)
                    {
                        txtZhangHao.Text = str.Trim();
                    }
                    sr.Close();
                }
      

  2.   

    插入大量的数
    例如一条数据是
    2011-08-26
    09:44:19,0.606,0,0,0.413,0,0,0,0,0,0.001,0,0,0,0,0,0,0,0,0.004,0,0,0.001,0,0,0.003,0,0,0,0,0,0.002,0,0,0.002,0,0,0.006,0,0,0.001,0,0,0.001,0,0,0.001,0,0
    其中在文件头写了表头 
    在插入时将其转换成一个长string 
    if (!File.Exists(strpath))
    {
        sw = new StreamWriter(strpath, true, Encoding.Default);
        sw.WriteLine(strwrite);
    }插入语句
    sw = new StreamWriter(strpath, true, Encoding.Default);
    oldb读取
    读取如题