关闭

VB数据库操作命令

1511人阅读 评论(1) 收藏 举报

连接数据库

引用 Microsoft ActiveX Data Objects 2.8 Library

Private Sub Form_Load()

Dim cnn As ADODB.Connection
Set cnn = New ADODB.Connection
 cnn.Provider = "Microsoft.Jet.OLEDB.4.0"
Dim cnnFile As String
 cnnFile = "Data Source=D:/db.mdb;Persist Security Info=False;Jet OLEDB:Database Password=123456789"
cnn.Open cnnFile

Dim rs As ADODB.Recordset
 Set rs = New ADODB.Recordset
 rs.Open Table, cnn, , adLockReadOnly
 Set Me.MSHFlexGrid1.DataSource = cnn2.Execute("select * from Table")


'ADO 连接 加密Access数据库
cnn2string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "D:/db.mdb;Persist Security Info=False;Jet OLEDB:Database Password=123456789"

 

添加

strSQL = "INSERT INTO User_Table(UserID,UserPWD,UserLevel,UserINFO) VALUES('" & Text1(0).Text & "','" & Text1(1).Text & "','" & Combo1.Text & "','" & Text1(2).Text & "')"
        rs.Open strSQL, cnn, adOpenDynamic, adLockOptimistic

删除

strSQL = "DELETE FROM User_Table WHERE UserID='" & Text1(0).Text & "'"
rs.Open strSQL, cnn, adOpenDynamic, adLockOptimistic

Update

        strSQL = "SELECT * FROM User_Table WHERE UserID='" & Text1(0).Text & "'"
        rs.Open strSQL, cnn, adOpenDynamic, adLockOptimistic
        rs.Update "UserPWD", Text1(1).Text
        rs.Update "UserLevel", Combo1.Text
        rs.Update "UserINFO", Text1(2).Text

或 UPDATE 数据表名 SET 新数据值 WHERE 条件表达式

UPDATE User_Table SET UserPWD=Text1(1).Text WHERE UserID=Text1(0).Text

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:144769次
    • 积分:2111
    • 等级:
    • 排名:第18704名
    • 原创:61篇
    • 转载:12篇
    • 译文:0篇
    • 评论:32条
    文章分类
    最新评论
    友情链接