如何在vb.net中创建参数化查询? [英] How to create parameterized queries in vb.net?

查看:232
本文介绍了如何在vb.net中创建参数化查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将参数化查询与ms Access 2003集成一起使用.根据不同的标准搜索任何数据.

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

推荐答案

您将需要使用访问.

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

这篇关于如何在vb.net中创建参数化查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆