为何老是增加不了字段呢?
时间:2010-10-15
来源:互联网
用vba操作Access时使用语句:
cnn.Execute "alter table temp_bom add column id char(25)"
怎么不能增加一个新的字段?
就是想在表里加一个字段ID 自动编号的那种.
cnn.Execute "alter table temp_bom add column id char(25)"
怎么不能增加一个新的字段?
就是想在表里加一个字段ID 自动编号的那种.
作者: moyandukang 发布时间: 2010-10-15
Private Sub sin()
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim sql As String
cnn.Open "provider=microsoft.jet.oledb.4.0;data source=" & ThisWorkbook.Path & "\mydb.mdb"
sql = "alter table ruku add column id counter"
cnn.Execute sql
Set cnn = Nothing
End Sub
也可把column省略为alter table ruku add id counter
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim sql As String
cnn.Open "provider=microsoft.jet.oledb.4.0;data source=" & ThisWorkbook.Path & "\mydb.mdb"
sql = "alter table ruku add column id counter"
cnn.Execute sql
Set cnn = Nothing
End Sub
也可把column省略为alter table ruku add id counter
作者: bibisin 发布时间: 2010-10-16
bibisin老师,你好
我发现单纯用你的代码确实能向Access里已经存在的表增加字段.
但在我程序里面要增加字段的表是用代码生成的,就增加不了字段,不知道为什么:
jx = UserForm2.ComboBox1.Value
zjmc = UserForm2.ComboBox2.Value
cnn.Execute "select * into temp_bom from bom where 机型 ='" & jx & " ' and 组件名称 = '" & zjmc & "' order by 机型,组件名称,单价 desc"
cnn.Execute "alter table temp_bom add column id counter"
是不是需要生成新表并刷新数据库之后才能增加字段? 请帮助解决.
[ 本帖最后由 moyandukang 于 2010-10-16 13:01 编辑 ]
我发现单纯用你的代码确实能向Access里已经存在的表增加字段.
但在我程序里面要增加字段的表是用代码生成的,就增加不了字段,不知道为什么:
jx = UserForm2.ComboBox1.Value
zjmc = UserForm2.ComboBox2.Value
cnn.Execute "select * into temp_bom from bom where 机型 ='" & jx & " ' and 组件名称 = '" & zjmc & "' order by 机型,组件名称,单价 desc"
cnn.Execute "alter table temp_bom add column id counter"
是不是需要生成新表并刷新数据库之后才能增加字段? 请帮助解决.
[ 本帖最后由 moyandukang 于 2010-10-16 13:01 编辑 ]
作者: moyandukang 发布时间: 2010-10-16
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28