2016-12-04 142 views
0

我有打开的csv文件的问题,我有错误“找不到ISAM”。我试图改变连线,但我没有发现一个错误。我该如何修复它?阅读csv Oldb c#

private void button7_Click(object sender, EventArgs e) 
    { 
     openFileDialog1.Filter = "CSV|*.csv"; 
     openFileDialog1.ValidateNames = true; 
     openFileDialog1.Multiselect = true; 
     if (openFileDialog1.ShowDialog() == DialogResult.OK) 
      textBox2.Text = openFileDialog1.FileName; 
    } 

    private void button8_Click(object sender, EventArgs e) 
    { 
     try 
     { 
      // string stringconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + textBox2.Text + ";Extended Properties=\"Text;HDR=Yes;FORMAT=Delimited\""; 
      string stringconn = "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=" + textBox2.Text + ";Extended Properties=text;HDR=Yes;FMT=Delimited"; 
      string file = System.IO.Path.GetFileName(textBox2.Text); 
      OleDbConnection cons = new OleDbConnection(stringconn); 
      OleDbDataAdapter dat = new OleDbDataAdapter("Select * from" + file, cons); 
      dat.Fill(dt); 
      dataGridView1.DataSource = dt; 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.Message); 
     } 
    } 

回答

2
string stringconn = "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=" + textBox2.Text + ";Extended Properties='text;'"; 

尝试增加单引号扩展Propetries

+0

确定它的工作原理,但i的值如何为三列分享它在一个不是所有的? – Ops

+0

你的意思是HDR和FMT? 'Extended Properties ='text; HDR = Yes; FMT = Delimited'' – jmesolomon

+0

谢谢你,伙计:) – Ops