I am trying to insert data into a database using a sign in form, but the code does not seem to work. No error occurs, it just looks like nothing is happening when I run the code.
Code:
Imports System.Data.OleDb
Public Class Form2
Dim provider As String
Dim datafile As String
Dim connstring As String
Dim myconnection As OleDbConnection = New OleDbConnection
Dim Mode As String
Private Sub btnSignin_Click(sender As Object, e As EventArgs) Handles btnSignin.Click
' Enable the Insert / Update / Delete buttons.
btnSignin.Enabled = True
' Test for the Mode of the form and perform the necessary actions accordingly.
Select Case Mode
Case "INSERT" ' If the mode is INSERT, perform a new record insertion.
Try
' Declare the connection and command objects.
Dim connection As New OleDb.OleDbConnection
Dim command As New OleDb.OleDbCommand
' Set the ConnectionString property and open the database connection.
connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\Dentist Pat 2\Dentist Pat 2\Users.accdb;_Name=;_Surname=;_Username=;_Password=;"
connection.Open()
' Set the Connection and CommandText properties of the command.
command.Connection = connection
command.CommandText = "INSERT INTO Users (_Name,_Surname,_Password,_Username) VALUES (@Name,@Surname,@Password,@Username)"
' Declare and initialize the parameters required by the command object.
Dim parName = New OleDb.OleDbParameter("@Name", txtName.Text)
Dim parSurname = New OleDb.OleDbParameter("@Surname", txtSurname.Text)
Dim parUsername = New OleDb.OleDbParameter("@Username", txtUsername.Text)
Dim parPassword = New OleDb.OleDbParameter("@Password", txtPassword.Text)
' Add the parameters to the command object.
command.Parameters.Add(parName)
command.Parameters.Add(parSurname)
command.Parameters.Add(parUsername)
command.Parameters.Add(parPassword)
' Execute the command.
command.ExecuteNonQuery()
' Close the database connection.
connection.Close()
Catch ex As Exception
' Prompt the user with the exception.
MessageBox.Show("Sign In Complete")
End Try
End Select
Me.Hide()
Form3.ShowDialog()
End Sub
End Class