VB怎么实现用户管理的功能!添加用户,删除用户,实现用户登陆某系统的问题

VB怎么实现用户管理的功能!添加用户,删除用户,实现用户登陆某系统的问题,第1张

使用ADO实现和数据库的连接。

请把以下代码放到模块里面

Public Function ExeSql(ByVal sql As String) As ADODB.Recordset

sql = Trim$(sql)

Dim strpath As String

Dim conn As New ADODB.Connection

Dim rst As New ADODB.Recordset

'strpath = App.Path

'If Right(strpath, 1) <>"/" Then

'strpath = strpath &"/"

'End If

strpath = "\\192.168.0.131\本地磁盘 (F)\data.mdb"'这里放数据库文件路径

Set conn = New ADODB.Connection

Set rst = New ADODB.Recordset

conn.ConnectionString = "provider=microsoft.jet.oledb.4.0data source=" &strpath &"Mode=ReadWritePersist Security Info=False"

conn.ConnectionTimeout = 30

conn.Open

Set rst.ActiveConnection = conn

rst.LockType = adLockOptimistic

rst.CursorType = adOpenKeyset

rst.Open sql

Set ExeSql = rst

Set rst = Nothing

Set conn = Nothing

End Function

然后在需要使用的地方先声明dim rs as new adodb.recordset

使用set rs=exesql("select * from 数据表名")

这样就可以实现与数据库的交互了

添加用户使用

with rs

.addnew

rs.fields("字段名")=text1.text

......

.update

end with

删除用户使用

with rs

.delete

.upate

end with

如果上面的是TXET,下面是LIST的话。添加

Private Sub Command1_Click()

List1.AddItem Text1.Text

End Sub

删除的是

Private Sub Command2_Click()

Dim I

GR:

For I = 0 To List1.ListCount - 1

If List1.Selected(I) = True Then

List1.RemoveItem I

GoTo GR

End If

Next I

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11633905.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-17
下一篇2023-05-17

发表评论

登录后才能评论

评论列表(0条)

    保存