我正在使用以下代码并尝试通过给定参数获取数据。我不知道如何将参数值传递给我的查询。
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
con.ConnectionString = "
PROVIDER=Microsoft.Jet.OLEDB.4.0;
Data Source = D:\.Net Programs\DB Experiments\AddressBook.mdb"
con.Open()
sql = "SELECT * FROM tblContacts where Name=? and City=?"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "AddressBook")
con.Close()
我首先创建一个 OleDbCommand 对象并使用该对象创建一个 OleDbDataAdapter
Imports Data.OleDb
dim cmd as new OleDbCommand
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT * FROM tblContacts where Name=? and City=?"
' Here we add the parameters in the same order they appear in the
' CommandText. The Name of the paramters can be anything when using
' a Jet database, only the order is important.
cmd.Parameters.Add("@Name", OleDbType.VarChar).value = "SLaks"
cmd.Parameters.Add("@City", OleDbType.VarChar).value = "New-York"
Dim da as new OleDbDataAdapter(cmd)
' Here you can use the Data Adapter as you would normally do.
我希望这有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)