Dim str As String Dim conn As Connection Dim rs As Recordset Private Sub display() Text1.Text = rs!user Text2.Text = rs!Name Text3.Text = rs!Password Text4.Text = rs!Password Text5.Text = rs!qxEnd SubPrivate Sub cmdOK_Click()
If cmdok.Caption = "更 新" Then rs.Update cmdok.Caption = "保 存" Command6.Caption = "取 消" Text1.Enabled = True Text2.Enabled = True Text3.Enabled = True Text4.Enabled = True Text5.Enabled = True Text1.SetFocus Command1.Enabled = False Command2.Enabled = False Command3.Enabled = False Command4.Enabled = False Else rs!user = Text1.Text rs!Name = Text2.Text rs!qx = Text5.Text If Text3.Text = Text4.Text Then rs!Password = Text3.Text rs.Update Text1.Enabled = False Text2.Enabled = False Text3.Enabled = False Text4.Enabled = False Text5.Enabled = False rs.MoveFirst display Command1.SetFocus cmdok.Caption = "更 新" Else If MsgBox("请确认密码一致性", vbInformation, "错误") = vbOK Then End If End If End If
End SubPrivate Sub Command1_Click()
rs.MoveFirst display
End SubPrivate Sub Command2_Click()
With rs .MovePrevious If .BOF Then .MoveFirst End With display
End SubPrivate Sub Command3_Click() With rs .MoveNext If .EOF Then .MoveLast End With display
这样 Set conn = New Connection Set rs = New Recordset和 直接在窗体上放一个adodc起的作用一样吗?
dim conn as new adodb.connection dim rs as new adodb.recordsetconn.open cnstring(连接字符串)rs.open "select * from table",conn,3,2 text1.text=rs("rs1.name") text2.text=rs("rs2.name") text3.text=rs("rs3.name") rs.close conn.close 只要你修改文本框里面的记录然后保存就可以了
Dim cn As New Adodb.Connection cn.Open "连接字符串" cn.Execute "Update TableName Set UserName='" & Trim(Text2.Text) & "'" _ & ",Password='" & Trim(Text3.Text) & "'" _ & "Where UserID='" & Trim(Text1.Text) & "'"
Dim conn As Connection
Dim rs As Recordset
Private Sub display() Text1.Text = rs!user
Text2.Text = rs!Name
Text3.Text = rs!Password
Text4.Text = rs!Password
Text5.Text = rs!qxEnd SubPrivate Sub cmdOK_Click()
If cmdok.Caption = "更 新" Then
rs.Update
cmdok.Caption = "保 存"
Command6.Caption = "取 消"
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True
Text1.SetFocus
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Else
rs!user = Text1.Text
rs!Name = Text2.Text
rs!qx = Text5.Text
If Text3.Text = Text4.Text Then
rs!Password = Text3.Text
rs.Update
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
rs.MoveFirst
display
Command1.SetFocus
cmdok.Caption = "更 新"
Else
If MsgBox("请确认密码一致性", vbInformation, "错误") = vbOK Then
End If
End If End If
End SubPrivate Sub Command1_Click()
rs.MoveFirst
display
End SubPrivate Sub Command2_Click()
With rs
.MovePrevious
If .BOF Then .MoveFirst
End With
display
End SubPrivate Sub Command3_Click() With rs
.MoveNext
If .EOF Then .MoveLast
End With
display
End SubPrivate Sub Command4_Click()
rs.MoveLast
display
End SubPrivate Sub Command6_Click()
If cmdok.Caption = "保 存" Then
rs.CancelUpdate
cmdok.Caption = "更 新"
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command6.Caption = "退 出"
rs.MoveFirst
display
Command1.SetFocus
Else
Unload Me
End If
End SubPrivate Sub Form_Load() Set conn = New Connection
Set rs = New Recordset
sdbname = App.Path + "\home.mdb"
str = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Persist Security Info=False;" & "Data Source=" & sdbname & ";" & "Jet OLEDB:Database Password=" & sPassword & ";"
conn.Open str
rs.Open "name", conn, adOpenDynamic, adLockOptimistic, adCmdTableEnd Sub
txtFields(0).datafield = "Id"
txtFields(1).datafield = "Author"
---------再设置
txtfields(0).datasource =adodc1
txtfields(1).datasource =adodc1
-----------这样只是adodc1与记录集连接正确就行。
Set conn = New Connection
Set rs = New Recordset和
直接在窗体上放一个adodc起的作用一样吗?
dim rs as new adodb.recordsetconn.open cnstring(连接字符串)rs.open "select * from table",conn,3,2
text1.text=rs("rs1.name")
text2.text=rs("rs2.name")
text3.text=rs("rs3.name")
rs.close
conn.close
只要你修改文本框里面的记录然后保存就可以了
cn.Open "连接字符串"
cn.Execute "Update TableName Set UserName='" & Trim(Text2.Text) & "'" _
& ",Password='" & Trim(Text3.Text) & "'" _
& "Where UserID='" & Trim(Text1.Text) & "'"