Imports System.Data.OleDb
Public Class MainForm
Dim conn As New OleDbConnection
Dim cmd As OleDbCommand
Dim myread As OleDbCommand
Dim dt As New DataTable
Dim da As New OleDbDataAdapter(cmd)
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;DataSource=|DataDirectory|\ISIOLO.accdb"
End Sub
Private Sub BtnCreate_Click(sender As Object, e As EventArgs) Handles BtnCreate.Click
conn.Open()
cmd = conn.CreateCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = "INSERT INTO USERS(EMAIL,PASSWORD,DESIGNATION) VALUES(@Email,@Password,@Designation)"
cmd.Parameters.AddWithValue("@Email", TxtEmail.Text)
cmd.Parameters.AddWithValue("@Password", TxtPassword.Text)
cmd.Parameters.AddWithValue("@Designation", ComboDesignation.Text)
Try
cmd.ExecuteNonQuery()
Console.WriteLine(cmd.CommandText)
For Each parameter As OleDbParameter In cmd.Parameters
Console.WriteLine($"{parameter.ParameterName}: {parameter.Value}")
Next
conn.Close()
MessageBox.Show("successful")
PnlCreateAccount.Visible = False
Catch ex As Exception
MessageBox.Show(ex.Message)
conn.Close()
End Try
End Sub
End Class
ADD user into access TABLE - it has four columns:
USERID
EMAIL TEXT
PASSWORD TEXT
DESIGNATION TEXT
USER ID is auto-increment, can't seem to want to be left out
"Password" is a reserved word in Jet/ACE SQL, so you need to escape it when using it as an identifier:
Ideally, you should not be storing passwords in the database directly, but rather hashing them. You can then reasonably name your column
PasswordHashand avoid the issue altogether.