2009-12-04 40 views
1

在ms access 2003集成中使用參數化查詢。根據不同的標準搜索任何數據。如何在vb.net中創建參數化查詢?

+4

Stack Overflow? – ephilip 2009-12-04 13:27:35

+0

我同意ephilip,在SO上發佈這個,你會在2分鐘內得到5個答案。 ;) – Bobby 2009-12-04 13:50:11

+0

嘿傢伙感謝您的答覆,但你能告訴什麼是什麼? – 2009-12-05 00:26:33

回答

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