vba连接sqlserver数据库问题

vba连接sqlserver数据库问题,第1张

while( @beginMonth<=@endMonth)

begin

select

Execute

End With

Set rsActiveConnection = conn

rsOpen cmd

If rsRecordCount > 0 Then

connConnectionString = "Driver={SQL Server};server=HKTNSSK-SQ003;database=Microsoft CSS;Trusted_Connection=yes;"

connOpen

下面这段程序是连接数据库,并将excel表格内容写入数据库。代码如下:

Sub FYMXDL()

Dim XQID As Integer

Dim JZID As Integer

Dim FYID As Integer

Dim FBXZ As String '分包性质

Dim DW As String

Dim SARR(1 To 31) As Double

Dim rst As New ADODBRecordset

mYpath = ThisWorkbookPath & "\jzfydataaccdb"

Set cONn = CreateObject("ADODBConnection")

cONnConnectionString = "Provider=MicrosoftAceOleDB120;Data Source=" & mYpath

cONnConnectionString = cONnConnectionString & ";Jet OLEDB:Database "

cONnOpen

XQID = Cells(3, 2)Value

JZID = Cells(3, 5)Value

'清空改小区-建筑的费用明细

Sql = "delete from fymxb where 小区ID=" & XQID & " AND 建筑ID = " & JZID

cONnExecute Sql

Const kshh = 7

hh = kshh

Do While Cells(hh, 3)Value > 0

FYID = Cells(hh, 3)Value

FBXZ = Cells(hh, 11)Text

For i = 1 To 31

SARR(i) = Round(Cells(hh, 13 + i - 1)Value, 2)

Next i

Sql = "INSERT INTO fymxb(小区ID,建筑ID,费用ID,分包性质,工作量,单价合计_中标,人工费_中标, 主材费_中标, 辅材费_中标, 机械费_中标, 管理费_中标, 利润_中标,规费_中标,税金_中标,合价_中标,单价合计_标准成本,人工费_标准成本,主材费_标准成本,辅材费_标准成本,机械费_标准成本,管理费_标准成本,利润_标准成本,规费_标准成本,税金_标准成本,合价_标准成本,单价合计_实际成本,人工费_实际成本,主材费_实际成本,辅材费_实际成本,机械费_实际成本,管理费_实际成本,利润_实际成本,规费_实际成本,税金_实际成本,合价_实际成本) VALUES (" & XQID & ", " & JZID & ", " & FYID & ", '" & FBXZ & "'"

For i = 1 To 31

Sql = Sql & "," & SARR(i)

Next i

Sql = Sql & " )"

cONnExecute Sql

hh = hh + 1

Loop

End Sub

以上就是关于vba连接sqlserver数据库问题全部的内容,包括:vba连接sqlserver数据库问题、如何用vba代码将access数据库连接求代码、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9739845.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-01
下一篇 2023-05-01

发表评论

登录后才能评论

评论列表(0条)

保存