Database 更改DAO数据库引擎数据表';VB6中从数据类型dbInteger到dbLong的s列
我继承了一个遗留的VB6应用程序来维护,我的VB6已经有点生锈了Database 更改DAO数据库引擎数据表';VB6中从数据类型dbInteger到dbLong的s列,database,vb6,dao,data-access-object,Database,Vb6,Dao,Data Access Object,我继承了一个遗留的VB6应用程序来维护,我的VB6已经有点生锈了 我有一个DAO表,它有一个DAO.DataTypeEnum.dbInteger类型的字段,需要将其更改为DAO.DataTypeEnum.dbLong类型。是否有一种快捷方式vb6来设置此新数据类型并保留现有值,或者我是否需要创建一个临时列来存储数据,然后使用新数据类型删除并重新创建列,然后手动迁移数据?如果这是一次性作业,您可以打开Access数据库并更改数据类型。 否则,请在此帖子中添加评论 编辑:可以对数据库对象发出ALTE
我有一个DAO表,它有一个DAO.DataTypeEnum.dbInteger类型的字段,需要将其更改为DAO.DataTypeEnum.dbLong类型。是否有一种快捷方式vb6来设置此新数据类型并保留现有值,或者我是否需要创建一个临时列来存储数据,然后使用新数据类型删除并重新创建列,然后手动迁移数据?如果这是一次性作业,您可以打开Access数据库并更改数据类型。
否则,请在此帖子中添加评论 编辑:可以对数据库对象发出ALTER语句
CurrentDb.Execute "ALTER TABLE myTable ALTER Column myIntegerColumn Long"
如果这是一次性作业,则可以打开Access数据库并更改数据类型。
否则,请在此帖子中添加评论 编辑:可以对数据库对象发出ALTER语句
CurrentDb.Execute "ALTER TABLE myTable ALTER Column myIntegerColumn Long"
如果您的数据库引擎支持ALTER TABLE ALTER COLUMN,则可以。如果您使用的是Access数据库引擎(Jet.mdb、ACE.accdb等),则可以在(Jet 4.0和Access 2002以后)中使用ALTER列
在过去,我完全是通过代码来完成的。下面的代码在不使用ALTER COLUMN的情况下将字符串字段转换为浮点双精度。它使用不同的名称和正确的数据类型创建新字段,复制数据,删除原始字段,并将新字段重命名为原始名称。您可以很容易地将其调整为从整数到长
Dim fld As DAO.Field
' Cant just change the type of an existing field. '
' Instead have to create the new field with a temporary name, '
' fill it with the required data, delete the old MyField field '
' and then rename the new field. The renaming has to be done '
' with DAO - cant do it through SQL '
' Add TEMP_MyField field: required double field. Will be renamed later '
sSQL = "ALTER TABLE MyTable " & _
"ADD COLUMN TEMP_MyField DOUBLE NOT NULL "
dbDatabase.Execute sSQL, dbFailOnError
' Copy the MyField values to the TEMP_MyField field '
sSQL = "UPDATE MyTable SET TEMP_MyField = CDbl(MyField)"
dbDatabase.Execute sSQL, dbFailOnError
' Delete the original MyField field (the text field) '
sSQL = "ALTER TABLE MyTable DROP COLUMN MyField"
dbDatabase.Execute sSQL, dbFailOnError
' Need to refresh the TableDefs to make sure new field shows up '
dbDatabase.TableDefs.Refresh
' Get a reference to the temporary MyField field we just created '
Set fld = dbDatabase.TableDefs("MyTable").Fields("TEMP_MyField")
' Rename it to the final name we want it to have '
fld.Name = "MyField"
如果您的数据库引擎支持ALTER TABLE ALTER COLUMN,则可以。如果您使用的是Access数据库引擎(Jet.mdb、ACE.accdb等),则可以在(Jet 4.0和Access 2002以后)中使用ALTER列
在过去,我完全是通过代码来完成的。下面的代码在不使用ALTER COLUMN的情况下将字符串字段转换为浮点双精度。它使用不同的名称和正确的数据类型创建新字段,复制数据,删除原始字段,并将新字段重命名为原始名称。您可以很容易地将其调整为从整数到长
Dim fld As DAO.Field
' Cant just change the type of an existing field. '
' Instead have to create the new field with a temporary name, '
' fill it with the required data, delete the old MyField field '
' and then rename the new field. The renaming has to be done '
' with DAO - cant do it through SQL '
' Add TEMP_MyField field: required double field. Will be renamed later '
sSQL = "ALTER TABLE MyTable " & _
"ADD COLUMN TEMP_MyField DOUBLE NOT NULL "
dbDatabase.Execute sSQL, dbFailOnError
' Copy the MyField values to the TEMP_MyField field '
sSQL = "UPDATE MyTable SET TEMP_MyField = CDbl(MyField)"
dbDatabase.Execute sSQL, dbFailOnError
' Delete the original MyField field (the text field) '
sSQL = "ALTER TABLE MyTable DROP COLUMN MyField"
dbDatabase.Execute sSQL, dbFailOnError
' Need to refresh the TableDefs to make sure new field shows up '
dbDatabase.TableDefs.Refresh
' Get a reference to the temporary MyField field we just created '
Set fld = dbDatabase.TableDefs("MyTable").Fields("TEMP_MyField")
' Rename it to the final name we want it to have '
fld.Name = "MyField"
这是一个自动“升级”工具,不是一次性任务这是一个自动“升级”工具,不是一次性任务这是一个自动“升级”工具,不是一次性任务请查看上述答案是否有用。这是一个自动“升级”工具,不是一次性任务请查看上述答案是否有用。