vb.netacc

How to use parameterized queries in vb.net?


How to use parameterized queries in vb.net? Because I always wanted to make a program that could read an ms access database and display results based on your query.


Solution

  • Create the desired query using question marks in the place of your parameters

    Dim sql = "SELECT * FROM Students WHERE Name = ?"
    

    Then create a OleDbCommand object and set the appropriate values (CommandText and so on). Then add Parameters to the command object. Finally, execute it how you need. Eg as ExecuteReader.