如何向ACCESS 数据库中增加一个字段
用DAO向ACCESS里增加一个字段DimdbsAsDatabaseDimrsAsRecordsetDimmmAsFieldSetdbs=OpenDatabase("路径...
用 DAO 向ACCESS 里增加一个字段
Dim dbs As Database
Dim rs As Recordset
Dim mm As Field
Set dbs = OpenDatabase("路径")
Set rs = dbs.OpenRecordset("表")
不知道再怎么写了。 展开
Dim dbs As Database
Dim rs As Recordset
Dim mm As Field
Set dbs = OpenDatabase("路径")
Set rs = dbs.OpenRecordset("表")
不知道再怎么写了。 展开
3个回答
展开全部
Public Function TransactSQL(ByVal sql As String) As ADODB.Recordset
Dim cont As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strConnection As String
Dim strArray() As String
Set cont = New ADODB.Connection '创建连接
Set rs = New ADODB.Recordset
On Error GoTo transactsql_error
strConnection = "Provider = Microsoft.jet.oledb.4.0; data source=" & App.Path & "\cd1.mdb;"
strConnection = strConnection & "Persist Security Info=False;"
strArray = Split(sql) 'Split() 返回一个下标从零开始的一维数组
cont.Open strConnection '打开连接
If StrComp(UCase$(strArray(0)), "select", vbTextCompare) = 0 Then
rs.Open Trim$(sql), cont, adOpenKeyset, adLockOptimistic
Set TransactSQL = rs
iflag = 1
Else
cont.Execute sql
iflag = 1
End If
transactsql_exit:
Set rs = Nothing
Set cont = Nothing
Exit Function
transactsql_error:
MsgBox "查询错误:" & Err.Description
iflag = 2
Resume transactsql_exit
End Function
上面这个是一个数据库的动态链接,这块代码在模块里放着.
Dim rs As New ADODB.Recordset
Dim sql As String
sql = "select * from Lendcx" 'Lendcx是表名
Set rs = TransactSQL(sql)
rs.AddNew '添加新纪录
rs.Fields(0) = Trim(Combo3.Text)
rs.Fields(1) = Trim(Combo1.Text)
rs.Fields(2) = Trim(DTPicker1.Value)
rs.Fields(3) = Trim(Combo2.Text)
rs.Fields(4) = Trim(Text2.Text)
rs.Fields(5) = Trim(text3.Text)
rs.Update
rs.Close
你可以参考一下看看!
Dim cont As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strConnection As String
Dim strArray() As String
Set cont = New ADODB.Connection '创建连接
Set rs = New ADODB.Recordset
On Error GoTo transactsql_error
strConnection = "Provider = Microsoft.jet.oledb.4.0; data source=" & App.Path & "\cd1.mdb;"
strConnection = strConnection & "Persist Security Info=False;"
strArray = Split(sql) 'Split() 返回一个下标从零开始的一维数组
cont.Open strConnection '打开连接
If StrComp(UCase$(strArray(0)), "select", vbTextCompare) = 0 Then
rs.Open Trim$(sql), cont, adOpenKeyset, adLockOptimistic
Set TransactSQL = rs
iflag = 1
Else
cont.Execute sql
iflag = 1
End If
transactsql_exit:
Set rs = Nothing
Set cont = Nothing
Exit Function
transactsql_error:
MsgBox "查询错误:" & Err.Description
iflag = 2
Resume transactsql_exit
End Function
上面这个是一个数据库的动态链接,这块代码在模块里放着.
Dim rs As New ADODB.Recordset
Dim sql As String
sql = "select * from Lendcx" 'Lendcx是表名
Set rs = TransactSQL(sql)
rs.AddNew '添加新纪录
rs.Fields(0) = Trim(Combo3.Text)
rs.Fields(1) = Trim(Combo1.Text)
rs.Fields(2) = Trim(DTPicker1.Value)
rs.Fields(3) = Trim(Combo2.Text)
rs.Fields(4) = Trim(Text2.Text)
rs.Fields(5) = Trim(text3.Text)
rs.Update
rs.Close
你可以参考一下看看!
展开全部
Public Function TransactSQL(ByVal sql AsString) As ADODB.Recordset
Dim cont As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strConnection As String
Dim strArray() As String
Set cont = New ADODB.Connection '创建连接
Set rs = New ADODB.Recordset
On Error GoTo transactsql_error
strConnection = "Provider =Microsoft.jet.oledb.4.0; data source=" & App.Path &"\cd1.mdb;"
strConnection = strConnection &"Persist Security Info=False;"
strArray = Split(sql) 'Split() 返回一个下标从零开始的一维数组
cont.Open strConnection '打开连接
If StrComp(UCase$(strArray(0)),"select", vbTextCompare) = 0 Then
rs.Open Trim$(sql), cont, adOpenKeyset,adLockOptimistic
Set TransactSQL = rs
iflag = 1
Else
cont.Execute sql
iflag = 1
End If
transactsql_exit:
Set rs = Nothing
Set cont = Nothing
Exit Function
transactsql_error:
MsgBox "查询错误:" &Err.Description
iflag = 2
Resume transactsql_exit
End Function
上面这个是一个数据库的动态链接,这块代码在模块里放着.
Dim rs As New ADODB.Recordset
Dim sql As String
sql = "select * from Lendcx"'Lendcx是表名
Set rs = TransactSQL(sql)
rs.AddNew '添加新纪录
rs.Fields(0) = Trim(Combo3.Text)
rs.Fields(1) = Trim(Combo1.Text)
rs.Fields(2) = Trim(DTPicker1.Value)
rs.Fields(3) = Trim(Combo2.Text)
rs.Fields(4) = Trim(Text2.Text)
rs.Fields(5) = Trim(text3.Text)
rs.Update
rs.Close
Dim cont As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strConnection As String
Dim strArray() As String
Set cont = New ADODB.Connection '创建连接
Set rs = New ADODB.Recordset
On Error GoTo transactsql_error
strConnection = "Provider =Microsoft.jet.oledb.4.0; data source=" & App.Path &"\cd1.mdb;"
strConnection = strConnection &"Persist Security Info=False;"
strArray = Split(sql) 'Split() 返回一个下标从零开始的一维数组
cont.Open strConnection '打开连接
If StrComp(UCase$(strArray(0)),"select", vbTextCompare) = 0 Then
rs.Open Trim$(sql), cont, adOpenKeyset,adLockOptimistic
Set TransactSQL = rs
iflag = 1
Else
cont.Execute sql
iflag = 1
End If
transactsql_exit:
Set rs = Nothing
Set cont = Nothing
Exit Function
transactsql_error:
MsgBox "查询错误:" &Err.Description
iflag = 2
Resume transactsql_exit
End Function
上面这个是一个数据库的动态链接,这块代码在模块里放着.
Dim rs As New ADODB.Recordset
Dim sql As String
sql = "select * from Lendcx"'Lendcx是表名
Set rs = TransactSQL(sql)
rs.AddNew '添加新纪录
rs.Fields(0) = Trim(Combo3.Text)
rs.Fields(1) = Trim(Combo1.Text)
rs.Fields(2) = Trim(DTPicker1.Value)
rs.Fields(3) = Trim(Combo2.Text)
rs.Fields(4) = Trim(Text2.Text)
rs.Fields(5) = Trim(text3.Text)
rs.Update
rs.Close
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
从我看过的教科书里都没写能加字段的,都是进ACCESS去设置的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询