[Solved] Fetching VB Variables to insert with SQL Query [closed]


To link VB variables to an SQL query, you need to add parameters that store the variables and then use those parameters in your SQL command:

Using parameters

MyCommand = New SqlCommand("SELECT Height, Weight, DoB, Gender, FROM `User` WHERE Username = @Username", DatabaseConnection)

MyCommand.Parameters.AddWithValue("@Username", Username)

UPDATE: How to connect to database

'Leads to the database
Public Filename As String = $"{AppDomain.CurrentDomain.BaseDirectory}YourDatabase.accdb"
'The connection string is set
Public ConStr As String = $"PROVIDER=Microsoft.ACE.OLEDB.12.0;DATA Source = {Filename}"
'The connection to the database is defined
Public DatabaseConnection As OleDb.OleDbConnection = New OleDb.OleDbConnection(ConStr)

6

solved Fetching VB Variables to insert with SQL Query [closed]