複数のExcelファイルからデータをインポートするDataGridView
があります。しかし、データをインポートするたびに、以前のデータが上書きされます。次のExcelファイルを前のデータグリッドビューの最後に追加するにはどうすればよいですか?複数のデータソースをdatagridviewに追加するvb.net
If DataGridView1.RowCount > 0 Then
MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\Work\4pc_test1.xlsx;Extended Properties=Excel 12.0;")
'MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & fd.FileName & "';Extended Properties=Excel 8.0;")
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
MyCommand.TableMappings.Add("Table", "Net-informations.com")
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
'DataGridView1.DataSource = DtSet.Tables(0)
Dim tab As DataTable = DtSet.Tables(0)
DataGridView1.DataSource = tab
MyConnection.Close()
Else
'The below connection allows for the opening of .xls files and .xlsx. The one reamed out below doesnt open up .xls files.
MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\Work\4pc_test1.xlsx;Extended Properties=Excel 12.0;")
'MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & fd.FileName & "';Extended Properties=Excel 8.0;")
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
MyCommand.TableMappings.Add("Table", "Net-informations.com")
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
DataGridView1.DataSource = DtSet.Tables(0)
MyConnection.Close()
End If
DGV用に複数のデータソースを持つことはできません。それは私ですか、IfとElseブロックの両方が、同じDataTable変数を持っていることを除いて同じものです。 – Plutonix
何もないですが、16の質問をして18の回答を得ました。 1つしか受け入れずに1回だけ投票した。あなたが有益であることを知っている回答を受け入れると、あなたが好きな回答を見つけるのに役立ちます。 [ツアー]はそれを説明します。ソースが同一であれば、データテーブルに追加することができます。 – Plutonix