将多个表格复制到数据网格视图中

时间:2014-05-12 21:01:35

标签: c# winforms excel datagridview datagrid

如何将多个工作表中的数据复制到数据网格视图中。目前我从1张纸上复印如下:

string SheetName = this.cmbSheetNames.SelectedText.ToString();
System.Data.OleDb.OleDbDataAdapter MyCommand =
                            new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [" + SheetName + "$]", objConn);
MyCommand.Fill(DS);
object Dt4 = DS.Tables[0];
dgvUploads.DataSource = Dt4;

1 个答案:

答案 0 :(得分:0)

string SheetName = this.cmbSheetNames.SelectedText.ToString();
System.Data.OleDb.OleDbDataAdapter MyCommand = new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [" + SheetName + "$]", objConn);

System.Data.OleDb.OleDbDataReader reader = MyCommand.ExecuteReader();

dgvUploads.DataSource = reader;
dgvUploads.DataBind();