首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#读取指定的.dbf资料

2012-09-06 
C#读取指定的.dbf文件我想让现在这个系统读取.dbf、或者.xls文件,然后输出到dataGridView1里,现在读取的时

C#读取指定的.dbf文件
我想让现在这个系统读取.dbf、或者.xls文件,然后输出到dataGridView1里,现在读取的时候只限定.dbf 和 .xls文件,其他的文件不读取,怎么做?我写的代码是这样的。
是在openFileDialog里设置么?

C# code
   string filePath = textBox1.Text;    //文件路径,如:E:\a.dbf            FileInfo fi = new FileInfo(filePath);            string mulu = fi.DirectoryName;            string filename = fi.Name;            OleDbConnection conn = new OleDbConnection();            string table = filePath;            string connStr = @"Provider=VFPOLEDB.1;Data Source=" + mulu + ";Collating Sequence=MACHINE";            conn.ConnectionString = connStr;            conn.Open();            string sql = @"select * from " + filename;            OleDbDataAdapter da = new OleDbDataAdapter(sql, conn);            DataTable dt = new DataTable();            da.Fill(dt);            dataGridView1.DataSource = dt;


[解决办法]
openFileDialog1.Filter="*.xls|*.dbf;
[解决办法]
通过 openFileDialog 的 Filter 属性进行设置

this.openFileDialog1.Filter = "Excel files (*.xls)|*.xls";
表示只能打开 xls 文档
[解决办法]
openFileDialog1.Filter="*.xls|*.dbf;
[解决办法]
用OpenFileDialog,用FILEER属性设置筛选字符串。都是在USING SYSTEM.IO下的。


可以参看下面的文章http://blog.csdn.net/kkkkkxiaofei/article/details/7896575

热点排行