然后在FORM1窗体中添加ADODC控件和DATAGRID控件,将DATAGRID1的属性DATASOURCE选ADODC1,打开ADODC1控件属性页使用连接字符串,选生成,在提供者选项中选MICROSOFT
jet
4.0
OLE
DB
Provider,然后按要求连接数据库等。在ADODC1控件属性页使用连接字符串空白文本窗口中就有一长串字符串,注意该字符串可复制到程序代码用于编程。ADODC1控件属性页的数据源内有命令文本(SQL)编写窗口可编写SQL查询语言。该窗口的SQL语句可复制到程序代码用于编程。
此外一楼说的ACCESS数据库不支持共享修改,但可共享只读访问.
以下给出代码:
Private
Sub
Form_Load()
With
Adodc1
Adodc1.ConnectionString
=
"Provider=Microsoft.Jet.OLEDB.4.0Data
Source=E:\db1.mdbPersist
Security
Info=False"
Adodc1.RecordSource
=
"select
name
from
b1
order
by
name"
Adodc1.Refresh
DataGrid1.Refresh
End
With
End
Sub
改为如下,用循环方法,先在数据库中找到要修改记录的ID后, 再修改。Private Sub Commandxiugai_Click()
Dim K As Integer
Dim rs As ADODB.Recordset
Dim conn As ADODB.Connection
Dim sqlStr As String
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0Data Source=E:\雅颜の小铺会员管理系统\xinjianhy.mdbPersist Security Info=False"
sqlStr1 = "select * from xjhy”
rs.Open sqlStr1, conn, adOpenKeyset, adLockOptimistic
If Not rs.EOF Then
rs.MoveFirst
End If
For K = 1 To rs.RecordCount
If rs(”ID”)=trim(Text1.text) then
r提交修改s("MONEY”)=Val(Text3.Text)
rs.Update
MsgBox "修改成功!", vbOKOnly
Goto 100
End if
rs.MoveNext
Next K
MsgBox "修改失败!", vbOKOnly
100
Rs.close
Set conn=nothing
End sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)