0

帮助。在这条线上失败:adapter.Fill(ds); // ERROR 检查名称是否无效,它不包含无效字符或标点符号,并且不能太长。

        openFileDialog1.Title = "Выбрать файл";
        openFileDialog1.InitialDirectory ="C:\\";        
        openFileDialog1.Filter = "dbf файлы (*.dbf)|*.dbf";            
        openFileDialog1.FilterIndex = 2;           
        openFileD`ial`og1.RestoreDirectory = true;
        openFileDialog1.FileName = "";


         if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {
string fullPathname = openFileDialog1.FileName;
                    FileInfo fi = new FileInfo(fullPathname);
                    string open_b = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fi.Directory + ";Extended Properties=dBase 5.0;Mode=Read|Write|Share Deny None;Persist Security Info=True";
                    OleDbConnection con = new OleDbConnection();
                    con.ConnectionString = open_b;
                    con.Open();



                 string vibor_t = "Select * From '" + fi.Name + "'";
                //string vibor_t = "Select * From '" + Path.GetFileNameWithoutExtension(fi.Name) + "'";

                OleDbDataAdapter adapter = new OleDbDataAdapter(vibor_t, con);
                DataSet ds = new DataSet();
                adapter.Fill(ds);  // ERROR
                con.Close();
                this.dataGridView1.DataSource = ds.Tables[0];
4

1 回答 1

0

您必须从 fi.Name 中删除扩展名,并删除单个引号,如下所示:

string vibor_t = "Select * From " + Path.GetFilenameWithoutExtension(fi.Name);
于 2012-07-09T12:01:50.057 回答