本文介绍了从我的资源中的excel文件填充datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个从Excel文件填充的DataGridView
.问题是我想将Excel文件添加到我的资源中(如果可能),然后从那里填充DataGridView
.
我现在用这个:
I have a DataGridView
that I populate from an Excel file. The problem is I want to add the Excel file to my resources (if possible) then populate the DataGridView
from there.
I use this now:
Try
Dim MyConnection As System.Data.OleDb.OleDbConnection
'Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection _
("provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\coded\Vehicle\Vehicles.xls';Extended Properties=Excel 8.0;")
MyCommand = New System.Data.OleDb.OleDbDataAdapter _
("select * from [Sheet1$]", MyConnection)
MyCommand.TableMappings.Add("Table", "TestTable")
'DtSet = New System.Data.DataSet
MyCommand.Fill(DataSet1)
DataGridView1.DataSource = DataSet1.Tables(0)
MyConnection.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
推荐答案
这篇关于从我的资源中的excel文件填充datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!