VB把excel数据导入ACCESS

65 篇文章 1 订阅
529 篇文章 74 订阅

Dim SQL As String

Dim conn As ADODB.Connection

Set conn = New ADODB.Connection

Dim Constr As String

Constr = "PROVIDER = Microsoft.Jet.OLEDB.4.0;" & "Data Source=c:\db.mdb"

conn.Open Constr

SQL = "select *  into t2 from  [excel 8.0;database=c:\book1.xls].[sheet1$]"

conn.Execute SQL

conn.Close

Set conn = Nothing

http://www.cnblogs.com/wsoft/articles/1960028.html
 
xls文件到mdb,用AutoHotkey实现如下:
conn:=ComObjCreate("ADODB.connection")
connectionStrings := "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" A_ScriptDir "\test\TestDB.mdb"
conn.Open(connectionStrings)
 Sql:="Select * INTO test4 FROM [Excel 8.0;HDR=Yes;IMEX=1;DATABASE=X:\AHK\CSV\test.xls].[Sheet1$];"
conn.execute(Sql)
conn.Close
conn:=
return
 
建议用
Microsoft.ACE.OLEDB.12.0 代替Microsoft.Jet.OLEDB.4.0
用Excel 12.0 Xml; 代替Excel 8.0;
  • 0
    点赞
  • 3
    收藏
  • 0
    评论
Dim extend_str As String Dim execl_cnn As New ADODB.Connection Dim execl_rst As New ADODB.Recordset Dim execl_count_rst As New ADODB.Recordset '纪录数量 Dim execl_field_rst As New ADODB.Recordset Dim execl_strconn As String Dim execl_strcmd As String Dim execl_count_str As String Dim insertStr As String 操作oracle数据库的记录集 Dim rst As ADODB.Recordset CommonDialog1.ShowOpen extend_str = Right(CommonDialog1.FileName, 3) If (extend_str = "xls") Then execl_cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & CommonDialog1.FileName & _ ";Extended Properties=Excel 8.0;" ElseIf (extend_str = "dbf") Then execl_cnn.ConnectionString = "Provider=MSDASQL.1;Driver=Microsoft Visual Foxpro Driver;SourceType=DBF;DBQ=" & getDir (CommonDialog1.FileName) execl_cnn.Open End If If (extend_str = "xls") Then execl_strcmd = "SELECT * from `Sheet1$` " execl_count_str = "SELECT count(*) from `Sheet1$` " execl_field_rst.Open execl_count_str, execl_cnn If (execl_field_rst.Fields(0).Value = 0) Then execl_strcmd = "SELECT * from [" & getFileNoExt(getfile(CommonDialog1.FileName)) & "$] " execl_count_str = "SELECT count(*) from [" & getFileNoExt(getfile(CommonDialog1.FileName)) & "$] " End If execl_field_rst.Close ElseIf (extend_str = "dbf") Then execl_strcmd = "SELECT * from " & CommonDialog1.FileName execl_count_str = "SELECT count(*) from " & CommonDialog1.FileName End If execl_rst.Open execl_strcmd, execl_cnn execl_count_rst.Open execl_count_str, execl_cnn If (CommonDialog1.FileName "") Then '进度条设置 ProgressBar1.Min = 0 ProgressBar1.max = execl_count_rst.Fields(0).Value If (execl_rst.RecordCount) Then '如果有记录 If (Option1.Value) Then '如果是仪器总库 If (execl_rst.Fields.Count = 8) Then Set rst = yg_gain_table_recordset("yg_device") execl_rst.MoveFirst Do While (Not execl_rst.EOF) rst.AddNew rst.Fields(0).Value = yg_getNextId("yg_device_id") rst.Fields(1).Value = execl_rst.Fields(0).Value & "" rst.Fields(2).Value = execl_r

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:代码科技 设计师:Amelia_0503 返回首页
评论
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值