用于选择DBF文件的Openfiledialog错误

时间:2012-07-09 11:51:44

标签: c# ado.net

帮助。在这一行失败:adapter.Fill(ds); //错误检查名称是否无效,它不包含无效字符或标点符号,也不会太长。

        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];

1 个答案:

答案 0 :(得分:0)

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

string vibor_t = "Select * From " + Path.GetFilenameWithoutExtension(fi.Name);