如何读取数据库列中的所有数据 [英] How to read all data in a database column

查看:110
本文介绍了如何读取数据库列中的所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我环顾四周,试图找到循环访问我的访问数据库表中各列的最佳方法.我想知道是否有比我尝试使用的方法更灵活的方法.


代码:

I have looked around the net trying to find the best way to loop through the columns in my access database tables. I would like to know if there is a more flexible method than the one I am trying to use.


Code:

Dim conn = New OleDbConnection ("Connectionstring")
Conn.Open()
Dim CMD as new oleDb.oleDbCommand("Select * from Sig Database", Conn, Conn.BeginTransaction)
Dim DR = CMD.ExecuteReader
Do While DR.Read
Dim V1 = DR.item("Sig")   
Dim V2 = DR.item("threat")
Dim V3 = DR.item("Virus Name")
DataGridview1.Rows.Add(V1, V2, V3)
Loop
DR.Close
Conn.Close()




简而言之,我想比较计算机上每个文件中的字符串,以查看它是否与访问数据库中的字符串匹配.如果为true,则将找到的匹配字符串添加到列表框中.

提前非常感谢您

出于好奇,还有一个小问题:

我想知道是否有等同于流阅读器但用于访问数据库的等同物?也许文件流?还是通过字符串搜索获得更好的性能?




In short I am looking to compare my strings from each file on my computer to see if it matches a string in my access database. if true add the matching string found to a listbox.

Thank you very much in advance

Just one other small question out of curiosity:

I would like to know if there is an equivalent to stream reader but for access database?. Maybe File stream? or anything to get better performance from the string search?

推荐答案

正确的方法是,首先,仅读取所需的数据,其次,让数据库做它的工作.因此,您应该运行SQL,询问该列是否包含所需的值,而不是获取所有数据并在代码中进行字符串比较.
The correct way to do it is, first, only read the data you need and second, let the DB do it''s job. So, you should run SQL that asks if the column contains the value you want, not grab all the data and do string comparisons in code.


假设您必须在数据库中拥有信息, 这.循环播放不是一个坏选择.
将其添加到某个集合中而不是使用datagridview会更好-因为我猜您真的不希望看到数据?
我猜你将要流式传输文件,并通过datagridview查找匹配项?如果您有许多sig或许多文件,那将非常慢,因此您想尽可能地提高效率.

因此-将sig威胁和名称存储在某个列表中,例如List(of VirusDefinition)
然后您可以迭代该列表...
Assuming you have to have the info in your db, the. Looping as you are is not a bad option.
Adding to some collection rather than a datagridview would be better - as I''m guessing you don''t really want to see the data?
I''m guessing you''re going to stream in a file and the look through your datagridview looking for matches? That''s going to be pretty slow if you have many sigs or many files, so you want to be as efficient as should can.

So - store the sig threat and name in some collection like a List(of VirusDefinition)
Then you can iterate that list...
For each vid as VirusDefinition in myVirusDefinitions
If myTextFileInAString.Contains(vid.Sig) Then
    Do whatever you want to do
End if
Next


这篇关于如何读取数据库列中的所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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