473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to search a datatable-can I use sql on a vb2005 datatable?

Hello,

I need to store various values that I will need to look up later on. I have
been using hashtables and arraylists. But I can only store 2 items per row
in a hashtable - key, value, and only 1 item in an arraylist. Or, I could
create a class with various members and store that in a collection, or a
structure, ...

I was thinking, I could create a datatable and add data to the datatable.
But when I need to retrieve data from this table what is the best way to
search it? Can I use a sqldatareader on a datatable? like (pseudocode)

dim dtr as sqldatareader = "select * from datatable1 where recordID = 100"

Is something like this doable? What is the correct/best way to search a
datatable? I hope it isn't just to loop through all the rows.

Thanks,
Rich
Jun 27 '06 #1
4 5986
Rich,

You can use the
Datatable.Select 'returns collection, this is not SQL code before that you
think that
Datatable.Defaultview.rowfilter 'returns a collection search at dataview
DataTable.Defaultview.find 'returns an index
Rowcollection.find 'returns a collection

And I thought another one which won't come in my mind,

I hope this helps,

Cor
"Rich" <Ri**@discussions.microsoft.com> schreef in bericht
news:CC**********************************@microsof t.com...
Hello,

I need to store various values that I will need to look up later on. I
have
been using hashtables and arraylists. But I can only store 2 items per
row
in a hashtable - key, value, and only 1 item in an arraylist. Or, I could
create a class with various members and store that in a collection, or a
structure, ...

I was thinking, I could create a datatable and add data to the datatable.
But when I need to retrieve data from this table what is the best way to
search it? Can I use a sqldatareader on a datatable? like (pseudocode)

dim dtr as sqldatareader = "select * from datatable1 where recordID = 100"

Is something like this doable? What is the correct/best way to search a
datatable? I hope it isn't just to loop through all the rows.

Thanks,
Rich

Jun 28 '06 #2
If you go for lightning speed and the smallest footprint

i would say go for the structure , hashtable combo

however i would only recomend this if you have a primary key value pair
record layout like this
id data data2 data3 data4 data5 etc etc

if it could also be the case that you might need to search on one or more
of the data fields then a datatable is much more flexible

however if it is so that you need to seacrh on combinations or joins of
fields
well then i would store the values in a SQL capable database

regards

Michel Posseth [MCP]


"Rich" wrote:
Hello,

I need to store various values that I will need to look up later on. I have
been using hashtables and arraylists. But I can only store 2 items per row
in a hashtable - key, value, and only 1 item in an arraylist. Or, I could
create a class with various members and store that in a collection, or a
structure, ...

I was thinking, I could create a datatable and add data to the datatable.
But when I need to retrieve data from this table what is the best way to
search it? Can I use a sqldatareader on a datatable? like (pseudocode)

dim dtr as sqldatareader = "select * from datatable1 where recordID = 100"

Is something like this doable? What is the correct/best way to search a
datatable? I hope it isn't just to loop through all the rows.

Thanks,
Rich

Jun 28 '06 #3
Thank you all for your replies. I think Cor had a little more in mind what I
was looking for in that I am looking for methods to search a datatable. My
thinking is that if I pull of small dataset - say a few hundred records from
a sql server data source containing hundreds of thousands or maybe millions
of records, I would hate to have to keep going back to the database. So I
pull a small subset of data into a dataTable. But now I have to search on
that dataTable.
Datatable.Defaultview.rowfilter 'returns a collection search at dataview
DataTable.Defaultview.find 'returns an index
Rowcollection.find
<<

These methods seems like the methods I would be looking for. I don't
imagine it would be possible to search on more than one parameter would it?

Well thanks all for your replies.

Rich
"Rich" wrote:
Hello,

I need to store various values that I will need to look up later on. I have
been using hashtables and arraylists. But I can only store 2 items per row
in a hashtable - key, value, and only 1 item in an arraylist. Or, I could
create a class with various members and store that in a collection, or a
structure, ...

I was thinking, I could create a datatable and add data to the datatable.
But when I need to retrieve data from this table what is the best way to
search it? Can I use a sqldatareader on a datatable? like (pseudocode)

dim dtr as sqldatareader = "select * from datatable1 where recordID = 100"

Is something like this doable? What is the correct/best way to search a
datatable? I hope it isn't just to loop through all the rows.

Thanks,
Rich

Jun 28 '06 #4
Hello Rich ,
I think Cor had a little more in mind what I
was looking for in that I am looking for methods to search a datatable

Euh yes ,,,, is my english so bad ?? in my memory and after rereading i
fully comply with Cor`s answer my answer was an additive to his answer
and the fact of what you are currently using

to answer your question :
<snip my previous answer >
if it could also be the case that you might need to search on one or more
of the data fields then a datatable is much more flexible
</snip my previous answer>

so the answer is yes you can search on more then one field

example ( copied and pasted from one of my projects )

For Each dr As DataRow In dtObjecten.Select("Verwerk='True' AND
errorFataal='False'")
If BlnStop Then Exit Sub
ObjectsSelVerw.Add(dr.Item(1), dr.Item(1))
Next
regards

Michel Posseth [MCP]

"Rich" wrote:
Thank you all for your replies. I think Cor had a little more in mind what I
was looking for in that I am looking for methods to search a datatable. My
thinking is that if I pull of small dataset - say a few hundred records from
a sql server data source containing hundreds of thousands or maybe millions
of records, I would hate to have to keep going back to the database. So I
pull a small subset of data into a dataTable. But now I have to search on
that dataTable.

Datatable.Defaultview.rowfilter 'returns a collection search at dataview
DataTable.Defaultview.find 'returns an index
Rowcollection.find
<<

These methods seems like the methods I would be looking for. I don't
imagine it would be possible to search on more than one parameter would it?

Well thanks all for your replies.

Rich
"Rich" wrote:
Hello,

I need to store various values that I will need to look up later on. I have
been using hashtables and arraylists. But I can only store 2 items per row
in a hashtable - key, value, and only 1 item in an arraylist. Or, I could
create a class with various members and store that in a collection, or a
structure, ...

I was thinking, I could create a datatable and add data to the datatable.
But when I need to retrieve data from this table what is the best way to
search it? Can I use a sqldatareader on a datatable? like (pseudocode)

dim dtr as sqldatareader = "select * from datatable1 where recordID = 100"

Is something like this doable? What is the correct/best way to search a
datatable? I hope it isn't just to loop through all the rows.

Thanks,
Rich

Jun 29 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lance Hoffmeyer | last post by:
Hi all, Anyone know where I can find a python script to search ebay? I have been looking around but haven't found anything. I know there must be one somewhere so I am probably just looking in...
14
by: vic | last post by:
My manager wants me to develop a search program, that would work like they have it at edorado.com. She made up her requirements after having compared how search works at different websites, like...
2
by: Zambo via SQLMonster.com | last post by:
Hi! We have Sql Server 2000 in our server (NT 4). Our database have now about +350.000 rows with information of images. Table have lot of columns including information about image name, keywords,...
1
by: cyrvb | last post by:
Hello, I'm a very very newbie in C# I did start 2 days ago, I get Visual Stuido 2005 C# I try to understand how to manage the arrays I did write this
1
by: Harry Haller | last post by:
What is the fastest way to search a client-side database? I have about 60-65 kb of data downloaded to the client which is present in 3 dynamically created list boxes. The boxes are filled from 3...
4
by: BenCoo | last post by:
Hello, In a Binary Search Tree I get the error : Object must be of type String if I run the form only with the "Dim bstLidnummer As New BinarySearchTree" it works fine. Thanks for any...
1
by: cglewis03 | last post by:
Hello, I am trying to build a search form with several different options to choose from. Currently it is set up to open within the same window if a single option is selected and open within a...
13
by: Vai2000 | last post by:
Hi All, Planning to call the same search API which windows Search uses for searching , when u launch with Ctrl+F,you have the flexibility to provide a containing text! VB/C# any thing would work...
4
by: ravindarjobs | last post by:
hi...... i am using ms access 2003,vb6 i have a form. in that i have 2 buttons 1. start search 2 stop search when i click the "start search" button the fucntion SearchSystem() is called,...
13
by: jfarthing | last post by:
Hi everyone! I am using the script below to search a db. If the is more than one match in the db, all goes well. But if there is only one match in the db, nothing gets displayed. Any...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.