VB程序重置数据库

时间:2017-10-12 20:19:28

标签: vb.net ms-access

我正在VB.NET中创建一个程序,该程序使用数据库作为登录系统。我可以使用该程序创建一个帐户,它出现在数据库中。我也可以登录。但是如果我关闭程序并重新运行它,数据就会从数据库中消失。

这是表单1 - 用户看到的第一个表单。这是登录屏幕,包含2个文本框,一个登录按钮和一个创建帐户按钮。

Imports System.Data.OleDb

Public Class Form1
    Public connstring As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=ProgramDatabase.accdb"
    Public conn As New OleDbConnection(connstring)

    Private Sub btnCreate_Click(sender As Object, e As EventArgs) Handles btnCreate.Click
        FormCreate.Show()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        conn.Open()
        Dim SqlQuery As String = "SELECT * FROM tblLogin"
        Dim Da As OleDbDataAdapter = New OleDbDataAdapter(SqlQuery, conn)
        Dim ds As DataSet = New DataSet
        Da.Fill(ds, "LoginData")
        Dim Dt As DataTable = ds.Tables("LoginData")

        For Each row As DataRow In Dt.Rows
            If row.Item(1) = txtUserName.Text And row.Item(2) = txtPassword.Text Then
                MsgBox("Welcome.")
                Exit Sub
            End If
        Next
        MsgBox("Wrong.")
        conn.Close()
    End Sub

    Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
        FormForgot.Show()
    End Sub
End Class

这是创建帐户表单的代码。

0 个答案:

没有答案