OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "txt files (*.xls)|*.xls";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
    this.textBox1.Text = openFileDialog1.FileName;
}
string mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '" + strPath + "';Extended Properties=Excel 8.0";
OleDbConnection cnnxls = new OleDbConnection(textBox1.Text);
问题,提示路径不对,C:\f\f.xls
正确应该是C:\\f\\f.xls

解决方案 »

  1.   

    @"C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\KnowlgBaseSystem";这样写 绝对没问题 直接复制路径过来 前面加@
      

  2.   

    看不太明白,不过觉得应该这样:
    string mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '" + textBox1.Text + "';Extended Properties=Excel 8.0";
    OleDbConnection cnnxls = new OleDbConnection(mystring );
      

  3.   

    这跟正则表达式有什么关系?哪一行提示的错误,是这一行吗?
    string mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '" + strPath + "';Extended Properties=Excel 8.0";Data Source = 后加“'”做什么的?这样试下string mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source=" + strPath + ";Extended Properties=Excel 8.0";PS:strPath是什么,你的代码并没有给出
      

  4.   

    @就是不转意,也可以C:\\f\\f.xls