C#读取指定的.dbf资料
C#读取指定的.dbf文件
我想让现在这个系统读取.dbf、或者.xls文件,然后输出到dataGridView1里,现在读取的时候只限定.dbf 和 .xls文件,其他的文件不读取,怎么做?我写的代码是这样的。
是在openFileDialog里设置么?
------解决方案--------------------
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.****.net/kkkkkxiaofei/article/details/7896575
我想让现在这个系统读取.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.****.net/kkkkkxiaofei/article/details/7896575