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

WinForm 的正则表达式.在线等~请各位帮忙
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

------解决方案--------------------
不用反斜杠,全部用斜杠//试试看
------解决方案--------------------
@ "C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\KnowlgBaseSystem ";

这样写 绝对没问题 直接复制路径过来 前面加@
------解决方案--------------------
是 "\\ "不是 "// ",或者在前面加@
------解决方案--------------------
看不太明白,不过觉得应该这样:


string mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = ' " + textBox1.Text + " ';Extended Properties=Excel 8.0 ";
OleDbConnection cnnxls = new OleDbConnection(mystring );

------解决方案--------------------
这跟正则表达式有什么关系?

哪一行提示的错误,是这一行吗?
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是什么,你的代码并没有给出