lzth.net
当前位置:首页 >> ExCEl 怎样用VBA将数据导入到SQL数据库 >>

ExCEl 怎样用VBA将数据导入到SQL数据库

sub test()Set cnn = CreateObject("ADODB.Connection") Set rs = CreateObject("Adodb.Recordset")strCn= "Provider=sqloledb;Server=R9HDET7;Database=dbname;Uid=username;Pwd=password" cnn.Open strCn SQL = "" cnn.Open strCn '与数据库建...

你在EXCEL中增加一个列名为ID,后在VBA中写以下代码,并引用Microsoft ActiveX Data Objects 2.8后执行 Public Sub 写入SQL2008() Dim cnn As New ADODB.Connection Dim SQL As String, mydata As String, mytable As String Dim i% mydata = "KK...

用VBA将EXCEL内容一次性导入SQL '工具->引用->Microsoft ActiveX Date Object 2.0 Public Sub SaveData() Dim Cnn As ADODB.Connection Dim SQL As String Set Cnn = New ADODB.Connection '建立于数据库的链接 '这里根据你的实际值修改Connecti...

'工具->引用->Microsoft ActiveX Date Object 2.0Public Sub SaveData() Dim Cnn As ADODB.Connection Dim SQL As String Set Cnn = New ADODB.Connection '建立于数据库的链接 '这里根据你的实际值修改ConnectionString = "Driver=SQL Server;S...

Sub test() Dim cn As ADODB.Connection Dim strSQL As String Dim lngRecsAff As Long Dim Headers As Boolean Dim strConn As String Dim path As String On Error GoTo test_Error Headers = True path = "c:\20131212.xls" strConn = "Provi...

VBE 工具 引用,选中 Microsoft ActiveX Data Object 2.8 Library 我不清楚是不是UFDATA_013_2008表的VENDOR列的数据,如果不是,你自己改一下SQL语句吧,sql = "select VENDOR from UFDATA_013_2008" Sub SQL数据导入() Dim cn As New ADODB.Connec...

1、首先为导入文件设置一个按钮:(更新数据) 2、为“更新数据”按钮添加执行代码: Private Sub Command87_Click()If MsgBox("请准备好导入的文件!", vbOKCancel, "打印确认") = 1 ThenDim xdlj As String 'xdlj:相对路径Dim dklj As String 'd...

Dim conn As New ADODB.ConnectionconnStr = "Driver={SQL Server};DataBase=test;Server=(local);UID=sa;PWD=123"conn.Open connStr '连接数据库Dim rs As New Recordsetsql = "select * from a" '查看表ars.Open sql, conn, 3, 3if Not rs.EOF...

'sql完整例子Sub testSql() '定义连接对象 Dim cnn As New ADODB.Connection Dim rs As New ADODB.Recordset '定义连接字符串 Dim conStr As String Dim sqlstr As String '连接字符串-以下是连接MSSQL数据库 conStr = "Provider=sqloledb; " _ ...

百度经验有详细的图文文章(网页链接)介绍编程语句,注意一点,不同的数据库连接代码是不同的。 另外,例子代码是把表中的数据全部读到一个表里面,你可以然后在VLOOKUP填写表的BC列。

网站首页 | 网站地图
All rights reserved Powered by www.lzth.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com