I have a database linked to my VB.NET project using the data source wizard. I've created a log in form using a table in access that has the details required to log in.
The code is:
Imports System.Data Public Class Form1 Dim conn As OleDb.OleDbConnection Dim strSQL As String Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & _ "Data Source=C:\Users\Andy\Desktop\ComputingProject.accdb" Dim dbReader As OleDb.OleDbDataReader Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles btnUserLogin.Click conn = New OleDb.OleDbConnection(strConn) conn.Open() strSQL = "SELECT * FROM tblLoginDetails WHERE (Username LIKE ?) AND (Password Like ?)" Dim dbCmd As New OleDb.OleDbCommand(strSQL, conn) dbCmd.Parameters.AddWithValue("@Username", txtUsername.Text) dbCmd.Parameters.AddWithValue("@Password", txtPassword.Text) dbReader = dbCmd.ExecuteReader() Using dbReader If dbReader.Read() Then Dim strResult1 As String = dbReader.Item("Username") Dim strResult2 As String = dbReader.Item("Password") MessageBox.Show("Login Success", "Login") Form2.Show() Else MessageBox.Show("Login Failed", "Login") End If End Using conn.Close() End Sub End Class
The table in my database is called tblLoginDetails and the fieldnames are ID, Username and Password.
I now need help adding a new user to the system. To do this I would need a form to contain two textboxes and a button. One textbox relating to the Username Field and the other to the Password field. The button being the submit button.
Can anybody help me with the code to write the values entered in the two textboxes to the database when the submit button is clicked?
(I've tried to go into as much detail as neccessary, sorry if it comes off as I think you have no idea what to do.)