Hello,
I am creating a code that allows the user to insert data into textboxes and then have it stored in an Access database. The code that I used worked previously but since I added the second query, nothing is added to either tables. Here is my code:
Private Sub btnSetPassword_Click(sender As Object, e As EventArgs) Handles btnSetPassword.Click
provider = "Provider=Microsoft.ACE.OLEDB.12.0;"
dataFile = "Data Source=|DataDirectory|\UserDatabase.accdb"
connString = provider & dataFile
Dim query As String
query = ("INSERT INTO [Students] ([First_Name], [Surname], [Year]) VALUES ('" & FirstNameTextBox.Text & "', '" & SurnameTextBox.Text & "','" & SchoolYearTextBox.Text & "')")
Dim query2 As String
Dim ID As Integer
query2 = ("INSERT INTO [Users] ([StudentID], [Username], [Password]) VALUES ('" & ID & "', '" & UsernameTextBox.Text & "', '" & PasswordTextBox.Text & "')") 'WHERE StudentID = Students.StudentID")
Using conn As OleDbConnection = New OleDbConnection(connString)
dbUp = New OleDbCommand(query, conn)
dbup2 = New OleDbCommand(query2, conn)
Try
conn.Open()
dbUp.Parameters.AddWithValue("@First_Name", FirstNameTextBox.Text)
dbUp.Parameters.AddWithValue("@Surname", SurnameTextBox.Text)
dbUp.Parameters.AddWithValue("@Year", SchoolYearTextBox.Text)
ID = dbup2.ExecuteScalar()
dbup2.Parameters.AddWithValue("@StudentID", ID)
dbup2.Parameters.AddWithValue("@Username", UsernameTextBox.Text)
dbup2.Parameters.AddWithValue("@Password", PasswordTextBox.Text)
Thank you