database - vb.net as I query Access database and display it in listview?
问题描述
I'm creating a form where I can do the following: please see the image As you can see, I have a txt_id_up and txt_id_dw in the database I want to make the following query.
SELECT * FROM Tabla1
WHERE ID BETWEEN 3 AND 7;
where txt_id_up = 3, and txt_id_dw = 7;
Dim connection As OleDbConnection
Dim command As OleDbCommand
Dim data_reader As OleDbDataReader
'------------------------------
'connect to ms.access database
connection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source= data\base.accdb;Persist Security Info=False")
connection.Open()
'reading data from Tabla1 table
command = New OleDbCommand("SELECT * FROM Tabla1", connection)
data_reader = command.ExecuteReader
'----------------------------------
'here the code to show in listview1 is missing
'----------------------------------
and in passing I would like to ask another question, can only the following columns be shown in listview? Name Account
I clarify that I use the datagridview to see it in general and the listview for queries
解决方案
我不知道我是否收到您的问题,但如果您想从数据库中显示名称和帐户,我建议您使用DataGridView
.
在表单中添加一个DataGridView
控件并添加以下代码:
Dim connection As OleDbConnection
Dim command As OleDbCommand
Dim data_adapter As OleDbDataAdapter
'------------------------------
'connect to ms.access database
connection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source= data\base.accdb;Persist Security Info=False")
connection.Open()
'reading data from Tabla1 table
command = New OleDbCommand("SELECT Name, Account FROM Tabla1 WHERE ID BETWEEN 3 AND 7", connection)
data_adapter = New OleDbDataAdapter(command)
'add results to DataGridView1
Dim datatable as New DataTable("Table")
data_adapter.Fill(datatable)
DataGridView1.DataSource = datatable
推荐阅读
- redgate - 尝试激活 RedGate Multiscript 时“无法显示此页面”
- php - 无需服务器内存问题和手动修改即可获取异步的大数据 API
- jquery - Laravel 8 @push 到 @stack 使脚本无法按预期工作
- wpf - 如何将文本框值绑定到视图模型并通过按钮命令更新它?
- visual-studio - “使用未分配的局部变量‘结果’”
- reactjs - 反应路由器私有路由不渲染组件
- docker - 将 RabbitMQ 作为服务的 Gitlab 集成
- php - 在数据库中使用 HASH 后的密码 - 无法使用“真实”密码
- javascript - 如何在无窗口模式下使用 pywebview 评估 javascript
- python - 根据来自单独 df 的指定 START_DATE 和 END_DATE 对 Pandas df 进行分组