在vb中如何导入excel等数据库数据
最近在写一个vb程序,需要将excel数据库内的数据导入vb中,但是我不知道怎么做,希望各位高手帮我解答一番,谢谢
[解决办法]
Public filepath As String
Private Sub alldata_Click()
Dim adoCnn As New ADODB.Connection
Dim adoRst As New ADODB.Recordset
MSHFlexGrid1.FixedCols = 0 '添加MSHFlexGrid1控件,并去掉MSHFlexGrid最前面的列,就是最前面银灰色没数据的那列
On Error GoTo 100
filepath = Text1.Text '在text1中输入excel文件的路径
adoCnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & filepath & ";Extended Properties='Excel 8.0;HDR=Yes'"
adoRst.Open "Select * From [sheet1$] ", adoCnn, adOpenKeyset, adLockOptimistic
Set Me.MSHFlexGrid1.DataSource = adoRst
100:
If frmDataEnv.Text1.Text = "" Then MsgBox ("未选取excel文件")
End Sub