I am making a program in VB.NET that uses a database for a login system. I can create an account using the program and it appears in the database. I can log in to it as well. But if I close the program and re-run it, the data is gone from the database.
This is form 1 - the first form that the user sees. It's the login screen with 2 text boxes, a login button and a create account button.
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
This is the code for the creating an account form.