如何将vbnet接口连接到访问数据库 [英] How to connect vbnet interface to access database

查看:121
本文介绍了如何将vbnet接口连接到访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人帮助我,我正在为图书馆开发一个程序。称为Automated Library System,使用vb.net(带编译Vb studio 2010express)和Access Microsoft 2007作为数据库。我希望有人通过提供代码帮助我,主要是我想要的代码是用于连接数据库的接口。



这里是我尝试的代码做但只发生一个错误我不知道如何处理它基本上在线发生的错误:Dim da As New OleDb.OleDbDataAdapter(SELECT MemberNo as [ID],& _,

please帮助我处理它。上帝会祝福你。我的电子邮件是dushidav7@hotmail.com



以下是这些代码

I would like someone to help me, I'm developing a program for library. called Automated Library System, using vb.net (with compile Vb studio 2010express)with Access Microsoft 2007 as database. II would like someone to help me by providing codes, mostly of code I want are those for connecting interface to database.

Here down are codes of what I was trying to do but one error occured I don't know how handle it basically the error occured on line: Dim da As New OleDb.OleDbDataAdapter("SELECT MemberNo as [ID]," & _,
please help me to handle it. God will bless you. my email is dushidav7@hotmail.com

here below are those codes

Public Class frmMember

    Private Property con As Object


    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()

    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        Me.txtMemberNo.Text = ""
        Me.txtRegNo.Text = ""
        Me.txtStaffNo.Text = ""
        Me.txtFirstName.Text = ""
        Me.txtUsername.Text = ""
        Me.txtLastName.Text = ""
        Me.cboGender.Text = ""
        Me.txtDateOfRegistration.Text = ""
        Me.txtNationalIDNumber.Text = ""
        Me.txtAddress.Text = ""
        Me.txtCourse.Text = ""
        Me.txtDepartment.Text = ""
        Me.txtDesignation.Text = ""
        Me.txtMemberNo.Focus()

    End Sub
    Private Sub RefreshData()
   
        If Not con.State = ConnectionState.Open Then
            'open connection

        End If


        Dim da As New OleDb.OleDbDataAdapter("SELECT MemberNo as [ID]," & _
                                             "RegNo as [RegNo], FirstName, Username, LastName, Gender, DateOfRegistration, NationalIDNumber, Address, Course, Department, Designation" & _
                                             "FROM Member_TABLE ORDER BY MemberNo", con)

        Dim dt As New DataTable
        'fil data to datatable 
        da.Fill(dt)
        'offer data in data in data table into datagridview
        Me.dgvData.DataSource = dt
        'close connection
        con.close()


    End Sub
    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim cnn As New OleDb.OleDbCommand
        If con.State = ConnectionState.Open Then
            'open connection if it is not yet open
            con.Open()
        End If
        cnn.Connection = con
        'add data to table
        cnn.CommandText = "INSERT INTO Member(RegNo, StaffNo, FirstName, Username, LastName, Gender, DateOfRegistration, NationalIDNumber, Address, Course, Department, Designation, MemberNo)" & _
                          "VALUES(" & Me.txtMemberNo.Text & ",' " & txtRegNo.Text & "','" & txtStaffNo.Text & "','" & Me.txtFirstName.Text & " ','" & Me.txtUsername.Text & "','" & Me.txtLastName.Text & "','" & Me.cboGender.Text & _
                           Me.txtDateOfRegistration.Text & "','" & Me.txtNationalIDNumber.Text & "','" & Me.txtAddress.Text & "','" & Me.txtCourse.Text & "','" & Me.txtDepartment.Text & "','" & Me.txtDesignation.Text & "')"

        cnn.ExecuteNonQuery()
        'refresh data in list
        RefreshData()
        'close connection
        con.Close()
    End Sub


    Private Sub frmMember_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con = New OleDb.OleDbConnection
        con.ConnectionString = "PROVIDER= Microsoft.Jet.OleDb.4.0; DATA SOURCE =" & Application.StartupPath & "\C:\Users\DAVID\Pictures\Library Project\CUU_LIBRARY.accdb"
    End Sub
End Class

推荐答案

大卫,



我建议你从这里开始:如何使用Microsoft Visual Basic .NET连接到Microsoft Access数据库并检索数据 [ ^ ]。这是一步一步的教程。



解决方法:使用ADO.NET编辑Access数据库 [ ^ ] - 虽然在C#中,但非常好的文章。



请阅读以上文章和你找到解决方案。



示例代码:

http://www.homeandlearn.co.uk/net/nets12p1.html [ ^ ]

为初学者使用ADO.NET [ ^ ]
David,

I would suggest you to start here: How to use Microsoft Visual Basic .NET to connect to a Microsoft Access database and to retrieve data[^]. This is a step by step tutorial.

Walkthrough: Editing an Access Database with ADO.NET[^] - although in C#, but very good article.

Please, read above articles and you'll find solution.

Example code:
http://www.homeandlearn.co.uk/net/nets12p1.html[^]
Using ADO.NET for beginners[^]


这篇关于如何将vbnet接口连接到访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆