利用VB语句调用ACCESS数据库,将一张表的全部信息复制到另一张表中

如题,该怎么写语句两张表格的字段不是完全相同的
2024-11-20 18:32:20
推荐回答(1个)
回答1:

Private Sub Command1_Click()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSql As String
Set conn = OpenConnForAccess("test.mdb")
strSql = "insert into b select * from c"
RunTrans strSql, conn
end sub

Public Function OpenConnForAccess(ByVal FileName As String) As ADODB.Connection
Dim AdoConn As New ADODB.Connection
With AdoConn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileName & ";Persist Security Info=False"
.Open
End With
Set OpenConnForAccess = AdoConn
End Function

Public Function RunTrans(ByVal tranSql As String, ByVal AdoConn As ADODB.Connection)
With AdoConn
.BeginTrans
.Execute tranSql
.CommitTrans
End With
End Function

两张表格的字段不是完全相同的
___________________________
strSql = "insert into b(id,num) select id,num from c"