4 个解决方案
#1
if 表1=表2 then
'将表1读出,插入表2
else
'可用DTS将在两个库中导入导出
endif
'将表1读出,插入表2
else
'可用DTS将在两个库中导入导出
endif
#2
不知道你是把两个表的结构合在一起还是两个表的结构一样,只是把数据合在一起呢,
如果是前者,可以用下面的函数
'**功能:向现有的表添加一列
Public Function AddNewColumn(ByVal strTableName As String, _
ByVal strFieldName As String, _
ByVal strFieldType As String, _
Optional ByVal blnAllowNull As Boolean = True, _
Optional ByVal blnNumeric As Boolean = False, _
Optional ByVal strDefaultValue As String = "" _
) As Boolean
'参数说明: strTableName: 表名
' strFieldName: 字段名
' strFiledType: 字段的数据类型
' blnAllowNull: 是否允许空值,False:Not Null,True:Null
' blnNumeric: 是否数字类型,False:否,True:是
' strDefaultValue: 缺省值
'示例 : Call AddNewColumn("Orders","GetGoodsType","Varhcar(1)",False,False,"''")
'返回值 : 如果添加列成功,则返回True,否则返回False
Dim strSQL As String
Dim strDefault As String
Dim I As Integer
On Error GoTo errHandle
strSQL = ""
strSQL = strSQL & "SELECT Syscolumns.Name,Sysobjects.Name "
strSQL = strSQL & "FROM Syscolumns "
strSQL = strSQL & "INNER JOIN Sysobjects ON Syscolumns.ID=Sysobjects.ID "
strSQL = strSQL & "WHERE Syscolumns.Name='" & strFieldName & "' AND Sysobjects.Name='" & strTableName & "'"
MyCn.Execute strSQL, I
If I = 0 Then
If Trim(strDefaultValue) <> "" Then
strDefault = strDefaultValue
Else
If blnNumeric = False Then
strDefault = "''"
Else
strDefault = "0"
End If
End If
'插入字段
strSQL = ""
strSQL = strSQL & "Alter Table " & strTableName & " "
strSQL = strSQL & "Add " & strFieldName & " " & strFieldType & " "
If blnAllowNull = False Then strSQL = strSQL & "Not Null "
strSQL = strSQL & "Constraint DF_" & strTableName & "_" & strFieldName & " "
strSQL = strSQL & "Default " & strDefault
MyCn.Execute strSQL
'清除Null值
strSQL = ""
strSQL = strSQL & "Update " & strTableName & " Set "
strSQL = strSQL & strFieldName & "=" & strDefault & " "
strSQL = strSQL & "Where " & strFieldName & " Is Null "
MyCn.Execute strSQL
End If
AddNewColumn = True
Exit Function
errHandle:
MsgBox "无法向表添加列!" & vbCrLf & _
Err.Number & ":" & Err.Description, vbExclamation, ClueInfo
Err.Clear
AddNewColumn = False
End Function
如果只是想合并数据,那就很简单了,用程序控制:同时打开这两个表,选择纪录集就可以操作了 ,象楼上说的那样,就OK了!
如果是前者,可以用下面的函数
'**功能:向现有的表添加一列
Public Function AddNewColumn(ByVal strTableName As String, _
ByVal strFieldName As String, _
ByVal strFieldType As String, _
Optional ByVal blnAllowNull As Boolean = True, _
Optional ByVal blnNumeric As Boolean = False, _
Optional ByVal strDefaultValue As String = "" _
) As Boolean
'参数说明: strTableName: 表名
' strFieldName: 字段名
' strFiledType: 字段的数据类型
' blnAllowNull: 是否允许空值,False:Not Null,True:Null
' blnNumeric: 是否数字类型,False:否,True:是
' strDefaultValue: 缺省值
'示例 : Call AddNewColumn("Orders","GetGoodsType","Varhcar(1)",False,False,"''")
'返回值 : 如果添加列成功,则返回True,否则返回False
Dim strSQL As String
Dim strDefault As String
Dim I As Integer
On Error GoTo errHandle
strSQL = ""
strSQL = strSQL & "SELECT Syscolumns.Name,Sysobjects.Name "
strSQL = strSQL & "FROM Syscolumns "
strSQL = strSQL & "INNER JOIN Sysobjects ON Syscolumns.ID=Sysobjects.ID "
strSQL = strSQL & "WHERE Syscolumns.Name='" & strFieldName & "' AND Sysobjects.Name='" & strTableName & "'"
MyCn.Execute strSQL, I
If I = 0 Then
If Trim(strDefaultValue) <> "" Then
strDefault = strDefaultValue
Else
If blnNumeric = False Then
strDefault = "''"
Else
strDefault = "0"
End If
End If
'插入字段
strSQL = ""
strSQL = strSQL & "Alter Table " & strTableName & " "
strSQL = strSQL & "Add " & strFieldName & " " & strFieldType & " "
If blnAllowNull = False Then strSQL = strSQL & "Not Null "
strSQL = strSQL & "Constraint DF_" & strTableName & "_" & strFieldName & " "
strSQL = strSQL & "Default " & strDefault
MyCn.Execute strSQL
'清除Null值
strSQL = ""
strSQL = strSQL & "Update " & strTableName & " Set "
strSQL = strSQL & strFieldName & "=" & strDefault & " "
strSQL = strSQL & "Where " & strFieldName & " Is Null "
MyCn.Execute strSQL
End If
AddNewColumn = True
Exit Function
errHandle:
MsgBox "无法向表添加列!" & vbCrLf & _
Err.Number & ":" & Err.Description, vbExclamation, ClueInfo
Err.Clear
AddNewColumn = False
End Function
如果只是想合并数据,那就很简单了,用程序控制:同时打开这两个表,选择纪录集就可以操作了 ,象楼上说的那样,就OK了!
#3
那么请问在access里面怎么实现把相同表结构的数据和到一起?
#4
数据库中的追加
#1
if 表1=表2 then
'将表1读出,插入表2
else
'可用DTS将在两个库中导入导出
endif
'将表1读出,插入表2
else
'可用DTS将在两个库中导入导出
endif
#2
不知道你是把两个表的结构合在一起还是两个表的结构一样,只是把数据合在一起呢,
如果是前者,可以用下面的函数
'**功能:向现有的表添加一列
Public Function AddNewColumn(ByVal strTableName As String, _
ByVal strFieldName As String, _
ByVal strFieldType As String, _
Optional ByVal blnAllowNull As Boolean = True, _
Optional ByVal blnNumeric As Boolean = False, _
Optional ByVal strDefaultValue As String = "" _
) As Boolean
'参数说明: strTableName: 表名
' strFieldName: 字段名
' strFiledType: 字段的数据类型
' blnAllowNull: 是否允许空值,False:Not Null,True:Null
' blnNumeric: 是否数字类型,False:否,True:是
' strDefaultValue: 缺省值
'示例 : Call AddNewColumn("Orders","GetGoodsType","Varhcar(1)",False,False,"''")
'返回值 : 如果添加列成功,则返回True,否则返回False
Dim strSQL As String
Dim strDefault As String
Dim I As Integer
On Error GoTo errHandle
strSQL = ""
strSQL = strSQL & "SELECT Syscolumns.Name,Sysobjects.Name "
strSQL = strSQL & "FROM Syscolumns "
strSQL = strSQL & "INNER JOIN Sysobjects ON Syscolumns.ID=Sysobjects.ID "
strSQL = strSQL & "WHERE Syscolumns.Name='" & strFieldName & "' AND Sysobjects.Name='" & strTableName & "'"
MyCn.Execute strSQL, I
If I = 0 Then
If Trim(strDefaultValue) <> "" Then
strDefault = strDefaultValue
Else
If blnNumeric = False Then
strDefault = "''"
Else
strDefault = "0"
End If
End If
'插入字段
strSQL = ""
strSQL = strSQL & "Alter Table " & strTableName & " "
strSQL = strSQL & "Add " & strFieldName & " " & strFieldType & " "
If blnAllowNull = False Then strSQL = strSQL & "Not Null "
strSQL = strSQL & "Constraint DF_" & strTableName & "_" & strFieldName & " "
strSQL = strSQL & "Default " & strDefault
MyCn.Execute strSQL
'清除Null值
strSQL = ""
strSQL = strSQL & "Update " & strTableName & " Set "
strSQL = strSQL & strFieldName & "=" & strDefault & " "
strSQL = strSQL & "Where " & strFieldName & " Is Null "
MyCn.Execute strSQL
End If
AddNewColumn = True
Exit Function
errHandle:
MsgBox "无法向表添加列!" & vbCrLf & _
Err.Number & ":" & Err.Description, vbExclamation, ClueInfo
Err.Clear
AddNewColumn = False
End Function
如果只是想合并数据,那就很简单了,用程序控制:同时打开这两个表,选择纪录集就可以操作了 ,象楼上说的那样,就OK了!
如果是前者,可以用下面的函数
'**功能:向现有的表添加一列
Public Function AddNewColumn(ByVal strTableName As String, _
ByVal strFieldName As String, _
ByVal strFieldType As String, _
Optional ByVal blnAllowNull As Boolean = True, _
Optional ByVal blnNumeric As Boolean = False, _
Optional ByVal strDefaultValue As String = "" _
) As Boolean
'参数说明: strTableName: 表名
' strFieldName: 字段名
' strFiledType: 字段的数据类型
' blnAllowNull: 是否允许空值,False:Not Null,True:Null
' blnNumeric: 是否数字类型,False:否,True:是
' strDefaultValue: 缺省值
'示例 : Call AddNewColumn("Orders","GetGoodsType","Varhcar(1)",False,False,"''")
'返回值 : 如果添加列成功,则返回True,否则返回False
Dim strSQL As String
Dim strDefault As String
Dim I As Integer
On Error GoTo errHandle
strSQL = ""
strSQL = strSQL & "SELECT Syscolumns.Name,Sysobjects.Name "
strSQL = strSQL & "FROM Syscolumns "
strSQL = strSQL & "INNER JOIN Sysobjects ON Syscolumns.ID=Sysobjects.ID "
strSQL = strSQL & "WHERE Syscolumns.Name='" & strFieldName & "' AND Sysobjects.Name='" & strTableName & "'"
MyCn.Execute strSQL, I
If I = 0 Then
If Trim(strDefaultValue) <> "" Then
strDefault = strDefaultValue
Else
If blnNumeric = False Then
strDefault = "''"
Else
strDefault = "0"
End If
End If
'插入字段
strSQL = ""
strSQL = strSQL & "Alter Table " & strTableName & " "
strSQL = strSQL & "Add " & strFieldName & " " & strFieldType & " "
If blnAllowNull = False Then strSQL = strSQL & "Not Null "
strSQL = strSQL & "Constraint DF_" & strTableName & "_" & strFieldName & " "
strSQL = strSQL & "Default " & strDefault
MyCn.Execute strSQL
'清除Null值
strSQL = ""
strSQL = strSQL & "Update " & strTableName & " Set "
strSQL = strSQL & strFieldName & "=" & strDefault & " "
strSQL = strSQL & "Where " & strFieldName & " Is Null "
MyCn.Execute strSQL
End If
AddNewColumn = True
Exit Function
errHandle:
MsgBox "无法向表添加列!" & vbCrLf & _
Err.Number & ":" & Err.Description, vbExclamation, ClueInfo
Err.Clear
AddNewColumn = False
End Function
如果只是想合并数据,那就很简单了,用程序控制:同时打开这两个表,选择纪录集就可以操作了 ,象楼上说的那样,就OK了!
#3
那么请问在access里面怎么实现把相同表结构的数据和到一起?
#4
数据库中的追加