'首先建立两个连接 Sub Main() With con On Error Resume Next conAss.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=ShopAcc.mdb;" & _ "Persist Security Info=False" conAss.Open If conAss.State <> 1 Then MsgBox "连接数据库失败,请检查ODBC配置及服务器状态!", vbCritical, "连接错误" Set con = Nothing End End If .ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;" & _ "User ID=sa;Data Source=shop" .CursorLocation = adUseClient .Open If .State <> 1 Then MsgBox "连接数据库失败,请检查ODBC配置及服务器状态!", vbCritical, "连接错误" Set con = Nothing End End If frmLogin.Show End With End Sub
读取sql数据库 , 写入access数据表难点就是怎么创建表
Sub Main()
With con
On Error Resume Next
conAss.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=ShopAcc.mdb;" & _
"Persist Security Info=False"
conAss.Open
If conAss.State <> 1 Then
MsgBox "连接数据库失败,请检查ODBC配置及服务器状态!", vbCritical, "连接错误"
Set con = Nothing
End
End If
.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;" & _
"User ID=sa;Data Source=shop"
.CursorLocation = adUseClient
.Open
If .State <> 1 Then
MsgBox "连接数据库失败,请检查ODBC配置及服务器状态!", vbCritical, "连接错误"
Set con = Nothing
End
End If
frmLogin.Show
End With
End Sub
Function AddGdsid() As Boolean
Dim strAddGds As String
Dim strAddDepgds As String
'增加商品编码
strAddGds = "INSERT INTO gds " & _
"( gdsid, clsid, gdsdes, srtcde, spc, bsepkg, mftfct, taxrto, " & _
"saltaxrto, rfnprc, rfntaxprc, salprc, discctrl, isclsgds, isunngds, " & _
"istaxlbr, udtpsn, udtdtm, isstpsal, isstp, rctusedat ) VALUES ( " & _
"'" & txtGdsid & "', '" & txtClsid & "', '" & txtGdsdes & "', '" & txtSrtcde & _
"', '/', '/', '" & txtMftfct & "', 0.17, 0.17, 0, 0, " & _
txtSalprc & ", 'n', 'n', 'n', 'n', '0', '" & _
Format(Date, "yyyymmdd") & "000000', 'n', 'n', '" & Format(Date, "yyyymmdd") & "' )"
On Error GoTo AddErr
conAss.Execute strAddGds
con.Execute strAddGds'增加到柜组
strAddDepgds = "INSERT INTO depgds " & _
"( depid, gdsid, depdes, isvld, udtpsn, udtdtm ) VALUES ( " & _
"'" & txtDepid & "', '" & txtGdsid & "', '" & txtDepdes & "', 'y', '0', '" & _
Format(Date, "yyyymmdd") & "000000' )"
conAss.Execute strAddDepgds
con.Execute strAddDepgds MsgBox "新编码已保存!", vbInformation, "保存成功"
AddGdsid = True
Exit Function
AddErr:
MsgBox "新编码失败,错误原因:" & Err.Description, vbInformation, "保存失败"
AddGdsid = False
Exit Function
End Function
2、如果不在本地,只能通过建表的方式。
insert into openrowset('Microsoft.Jet.OLEDB.4.0',
'x:\A.mdb';'admin';'',A表) select * from sql的数据库名..SQL的数据表
1\事先建一个与SQL一样的结果的库(手工作就可以,如以下:sell.mdb).
2\打开SQL,打开ACCESS,把SQL的记录存到access.
3\用FileCopy "D:\\sell.mdb", "D:\sellbak.fwy"
4\sellbak.fwy就是备份文件.
5\导也就可以用sell.fwy导入了.是不是很简单呢