1、新增用户:sql=" insert into 表名 values ' " &用户 &" ' ' " &密码 &" ' "
2、修改:sql=" update
3、删除:sql=" detele * from 表 where 用户=' " &text1.text &" '
StrConnApp = "PROVIDER=Microsoft.Jet.OLEDB.4.0Data Source=" &"setting.mdb"
Dim ConnTemp As New OleDb.OleDbConnection
Dim StrSQL As String
ConnTemp.ConnectionString = StrConnApp
StrSQL = "Select Count(*) From userlist Where [UserID]='" &ComboBox1.Text &"' AND [UserPassword]='" &TextBox1.Text &"'"
使用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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)