Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,884 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Say I have 6 textboxes and there are 6 columns in the linked database, how would go about making a button at the end of the form save the text input into the textboxes as a new record in the Access database
Hello VOOIJOOEE,
Thank you for taking time to post this issue in Microsoft Q&A forum.
You can try following codes:
Imports System.Data.OleDb
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim n1 As String = TextBox1.Text
Dim n2 As String = TextBox2.Text
Dim n3 As String = TextBox3.Text
Dim n4 As String = TextBox4.Text
Dim n5 As String = TextBox5.Text
Dim n6 As String = TextBox6.Text
Using dbConn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source = C:\XXXX\XXXX.accdb")
dbConn.Open()
Dim strSql = "INSERT INTO XXXX (c1, c2, c3, c4, c5, c6) VALUES (?,?,?,?,?,?)"
Using objcmd = New OleDbCommand(strSql, dbConn)
objcmd.Parameters.AddWithValue("@c1", n1)
objcmd.Parameters.AddWithValue("@c2", n2)
objcmd.Parameters.AddWithValue("@c3", n3)
objcmd.Parameters.AddWithValue("@c4", n4)
objcmd.Parameters.AddWithValue("@c5", n5)
objcmd.Parameters.AddWithValue("@c6", n6)
objcmd.ExecuteNonQuery()
End Using
End Using
End Sub
End Class
Sincerely,
Tianyu