如何将vbnet接口连接到访问数据库

如何将vbnet接口连接到访问数据库

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

问题描述

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



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

please帮助我处理它。上帝会祝福你。我的电子邮件是[email protected]



以下是这些代码

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 [email protected]

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

推荐答案


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

08-28 16:42