How to create parameterized queries in vb.net?

前端 未结 2 548
误落风尘
误落风尘 2020-12-22 04:08

Using parameterized queries with ms access 2003 integration. To search any data according to different criteria.

2条回答
  •  醉梦人生
    2020-12-22 04:30

    You'll need to use the OleDbConnection class, as well as the OleDbCommand class, with the proper connection string for Access.

    Dim sql as String = "SELECT * FROM TABLE_A WHERE COLUMN_A = @PARAM"
    Dim connectionString as String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;"
    Using connection As New OleDbConnection(connectionString)
       Dim command As New OleDbCommand(sql)
       command.Connection = connection
       command.Params.Add("@PARAM", yourVariable)
       connection.Open()
        Dim reader As OleDbDataReader = command.ExecuteReader()
        While reader.Read()
            Console.WriteLine(reader.GetString(1)
        End While
    End Using
    

提交回复
热议问题