从数据库数据填充listview [英] populate listview from database data
问题描述
我想刷新并在vb.net win窗体中单击按钮时在listview中显示数据库数据.并单击该列表视图的特定行,另一个列表视图应以相同的形式显示来自同一数据库的所有数据.
任何人都可以为我提供确切的代码..紧急的..
i want to refresh and display database data in listview on button click in vb.net win form. and clicking on a particular row of that listview another listview should display the all data from same database in the same form.
can anyone provide me the exact code for this..its urgent..
推荐答案
在这里,您可能会不得不更改一些代码,尽管操作不便. :P
Here you go you might have to change some of the code though ill walk you through it :P
Dim db_con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "DATABASE LOCATION GOES HERE)
db_con.Open()
Dim ds As New DataSet
Dim query1 As String
query1 = " SELECT * FROM TABLEGOESHERE"
Dim da As OleDbDataAdapter
da = New OleDbDataAdapter(query1, db_con)
da.Fill(ds, "VirusMD5")
Dim tblstr As String = Nothing
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim _Ecount As Integer
_Ecount = ds.Tables("THE TABLE YOU NEED TO READ FROM").Rows.Count
signatures = _Ecount
cmd = New OleDbCommand("SELECT * FROM VirusMD5", db_con)
dr = cmd.ExecuteReader
While dr.Read
'You need to figure out how many items their are and what you are reading. See link below
Combobox1.Items.Add(dr(0))
'0 Stands for the first items rows are handled automatically.
End While
GoTo ende
End If
ende:
此图像将帮助您处理其中的项目和行部分(行和行始终从0开始)
www.homeandlearn.co.uk/NET/images/vb_2010/addressBook_ACCESS_p280.jpg [ ^ ]
我不对列表视图执行任何操作,因为我不熟悉它,但是从数据库获取数据是相同的.
要使其执行您想要的操作,请编辑代码的这一部分.
This image will help your with the items and rows part of it (rows and columes always start at 0)
www.homeandlearn.co.uk/NET/images/vb_2010/addressBook_ACCESS_p280.jpg[^]
I do not do anything we listviews because I am not familiar with it but getting the data from the database is the same.
To make it do what you want to do edit this part of the code.
Combobox1.Items.Add(dr(0))
将该行替换为向您的listveiw添加数据.希望对您有帮助
Replace that line with adding data to your listveiw. Hope this helps
这篇关于从数据库数据填充listview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!