标题:【求助】关于VB.Net基于OLE DB访问accdb数据库并进行操作?
只看楼主
屋顶有只猫
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-5-6
 问题点数:0 回复次数:3 
【求助】关于VB.Net基于OLE DB访问accdb数据库并进行操作?
在网上扒了N天也没结果,恳请各路英雄帮忙解决:
在VS2012的VB开发环境下实现基于OLE DB方式连接访问Access2007的accdb格式数据库,并对数据库的表格记录进行添加、修改、删除、查询等操作

我的连接字符串:
Dim ObjConn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\EPMIS.accdb;Persist Security Info=True;Jet OLEDB:Database Password=Admin")
其他就不知道该怎么办了

窗口有3个TextBox控件:TextBox1、TextBox2、TextBox3
      3个Button控件:添加、修改、删除
      1个TreeView控件:TreeView1
      1个DataGridView控件:DataGridView1
accdb数据库中有1个三字段表格[Data]:part1(主键),part2,part3

现需实现功能:
单击“添加”按钮→TextBox1、TextBox2、TextBox3中的内容分别存入accdb数据库里的[Data]表格对应的part1(主键),part2,part3字段中,即[Data]增加一个记录
单击“修改”按钮→DataGridView1中选中的记录被修改为TextBox1、TextBox2、TextBox3中的内容
单击“删除”按钮→TreeView1中选中的节点项被删除

能解决吗~~~~
搜索更多相关主题的帖子: 数据库 字符串 英雄 记录 开发 
2015-05-06 16:45
屋顶有只猫
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-5-6
得分:0 
虽然看不到希望,但也不要沉了,哪怕能够实现其中一种功能也是好的……
2015-05-07 11:00
lzb6689
Rank: 1
等 级:新手上路
帖 子:46
专家分:0
注 册:2007-11-9
得分:0 
有个例子:
VB连接读取ACCESS2007数据库accdb代码
Public cn As ADODB.Connection
Public rs As ADODB.Recordset
Private Sub Form_Load()
 Set rs = New ADODB.Recordset
 OpenDB
'Download by http://www.
  rs.Open "select * from Large", cn, 1, 3
  Do While Not rs.EOF
    Combo1.AddItem rs("Description")
    rs.MoveNext
  Loop
   
 End Sub

Sub OpenDB()
 Set cn = New ADODB.Connection
  Dim s As String
  
 s = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Large Scale Integrated Projects - 2 May 2011.accdb;Persist Security Info=False"
 cn.Open s
End Sub   
2015-05-08 13:11
lzb6689
Rank: 1
等 级:新手上路
帖 子:46
专家分:0
注 册:2007-11-9
得分:0 
例子:
   Private Sub SCList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles SCListZL.SelectedIndexChanged
        If Trim(Me.SCListZL.SelectedValue) = "铁" Then
            Dim chj, DW, JS, r, t As String
            Dim objdataset As New DataSet
            Dim objconn As New OleDbConnection
            Dim oleDbAdapter1 As OleDbDataAdapter
            Dim connstr As String, xt As String, s As String
            Dim objdccommand As OleDbCommand
            DW = Trim(Me.SCListCJ.SelectedValue)
            JS = Trim(Session("JiShu"))

            chj = "(主任审核 = '通过' and 科长审核 = '通过') and " + "(" + "车间 = '" + DW + "')"

            connstr = Trim(PLXTLJM)
            If connstr <> "" Then
                objconn.ConnectionString = connstr
                objconn.Open()
                xt = "20"
                If chj = "" Then
                    s = "select top " + Trim(xt) + " ID,车间,车间审核,科长审核,生产品种 from tbPeiLiao ORDER BY 日期 DESC"   '时间,
                Else
                    s = "select top " + Trim(xt) + " ID,车间,车间审核,科长审核,生产品种 from tbPeiLiao where " + Trim(chj) + " ORDER BY 日期 DESC" '时间
                End If

                oleDbAdapter1 = New OleDbDataAdapter(s, objconn)
                oleDbAdapter1.Fill(objdataset)
                Me.DataGridFSQ.DataSource = objdataset
                Me.DataGridFSQ.DataBind()
                objdataset.Clear()

                objdataset.Dispose()
                oleDbAdapter1.Dispose()
                objconn.Close()
                objconn.Dispose()
            End If
        End If
        If Trim(Me.SCListZL.SelectedValue) = "铁" Then
            Dim chj, DW, JS, r, t As String
            Dim objdataset As New DataSet
            Dim objconn As New OleDbConnection
            Dim oleDbAdapter1 As OleDbDataAdapter
            Dim connstr As String, xt As String, s As String
            Dim objdccommand As OleDbCommand
            DW = Trim(Me.SCListCJ.SelectedValue)
            JS = Trim(Session("JiShu"))

            chj = "(主任审核 = '通过' and 科长审核 = '通过') and " + "(" + "车间 = '" + DW + "')"

            connstr = Trim(PLXTLJM)
            If connstr <> "" Then
                objconn.ConnectionString = connstr
                objconn.Open()
                xt = "20"
                If chj = "" Then
                    s = "select top " + Trim(xt) + " ID,车间,车间审核,科长审核,生产品种 from tbPLMnFe ORDER BY 日期 DESC"   '时间,
                Else
                    s = "select top " + Trim(xt) + " ID,车间,车间审核,科长审核,生产品种 from tbPLMnFe where " + Trim(chj) + " ORDER BY 日期 DESC" '时间
                End If

                oleDbAdapter1 = New OleDbDataAdapter(s, objconn)
                oleDbAdapter1.Fill(objdataset)
                Me.DataGridFSQ.DataSource = objdataset
                Me.DataGridFSQ.DataBind()
                objdataset.Clear()

                objdataset.Dispose()
                oleDbAdapter1.Dispose()
                objconn.Close()
                objconn.Dispose()
            End If
        End If
    End Sub
2015-05-08 13:28



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-444907-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.089295 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved