或者,直接用 ADOX 更改 TABLE 的 Columns(字段名) 对象的 NAME 属性即可。
Function Test()
ChangeTableFieldName_ADO "表1", "aa", "pic1"
End Function
Function ChangeTableFieldName_ADO(MyTableName As String, MyFieldName As String, strNewName As String)
'3个参数:
'MyTableName 字符串,表名
'MyFieldName 字符串,原来的字段名
'strNewName 字符串,新的字段名
'记得先引用 ADOX
Dim MyDB As New ADOX.Catalog
Dim MyTable As ADOX.Table
MyDB.ActiveConnection = CurrentProject.Connection
Set MyTable = MyDB.Tables(MyTableName)
MyTable.Columns(MyFieldName).Name = strNewName
End Function
'修改表名要引用.Microsoft ADO Ext. 2.X for DDL and SecurityPrivate Sub Command1_Click()
Dim db As New ADODB.Connection
db.ConnectionString = "provider=microsoft.jet.oledb.4.0" &"data source=" &App.Path &"\database.mdb"
db.Open
RenameTableName db, "oldTableName", "newTableName"
End Sub
'RenameTableName的返回值-1表示出错.
' 0表示没有存在要修改的表.
'1 表示成功
Public Function RenameTableName(DatabseConnectionObject As ADODB.Connection, strOldName As String, strNewName As String) As Integer
On Error GoTo acd
Dim tbl As ADOX.Table, cat As New ADOX.Catalog
Set cat.ActiveConnection = DatabseConnectionObject '设置目录的链接
RenameTableName = 0
For Each tbl In cat.Tables
If LCase(tbl.Name) = LCase(strOldName) Then
tbl.Name = strNewName '重命名表的名称
RenameTableName = 1
End If
Next
Exit Function
acd:
RenameTableName = -1
End Function
你的问题才没有说清楚你把SQL语句写好了直接执行这个SQL语句就可以了,不管你是添加,修改还是删除语句,和你的ID自动编号没有什么关系吧?
delete table where id=@id
也可以直接写,不带参数的
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)