如何在vb.net中创建参数化查询?

时间:2009-12-04 13:25:14

标签: vb.net ms-access

使用ms access 2003集成的参数化查询。根据不同的标准搜索任何数据。

2 个答案:

答案 0 :(得分:3)

您需要使用OleDbConnection类以及OleDbCommand类,并使用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

答案 1 :(得分:0)

您可能会发现这有用:Howto? Parameters and LIKE statement SQL