我正在制作一个将两个数据库合并在一起的程序......我可以使用以下代码将 excel 电子表格导入 DataGridView:
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\test.xls;Extended Properties=""Excel 8.0;HDR=YES;IMEX=1""";
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
DbDataAdapter adapter = factory.CreateDataAdapter();
DbCommand selectCommand = factory.CreateCommand();
selectCommand.CommandText = "SELECT * FROM [All Carpets to Excel$]";
DbConnection connection = factory.CreateConnection();
connection.ConnectionString = connectionString;
selectCommand.Connection = connection;
adapter.SelectCommand = selectCommand;
data = new DataSet();
adapter.Fill(data);
dataGridView1.DataSource = data.Tables[0].DefaultView;
我遇到的问题是我试图找到一种方法将源文件更改为对话框返回的路径。我有一个包含文件路径的字符串文件。如何将其合并到连接字符串中?
或者也许有更好的方法来做到这一点?
谢谢!
卢克