473,782 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6016
Rich,

You can use the
Datatable.Selec t 'returns collection, this is not SQL code before that you
think that
Datatable.Defau ltview.rowfilte r 'returns a collection search at dataview
DataTable.Defau ltview.find 'returns an index
Rowcollection.f ind 'returns a collection

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

I hope this helps,

Cor
"Rich" <Ri**@discussio ns.microsoft.co m> schreef in bericht
news:CC******** *************** ***********@mic rosoft.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.Defau ltview.rowfilte r 'returns a collection search at dataview
DataTable.Defau ltview.find 'returns an index
Rowcollection.f ind
<<

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.Sele ct("Verwerk='Tr ue' AND
errorFataal='Fa lse'")
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.Defau ltview.rowfilte r 'returns a collection search at dataview
DataTable.Defau ltview.find 'returns an index
Rowcollection.f ind
<<

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
3270
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 the wrong places. Optimally, I would like the script to search ebay and then send an email out with the results. Lance
14
4634
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 eBay, Yahoo and others. This is what she wants my program to be able to do: (try this test at different websites just for fun). At eBay: - enter the word 'television' in a search field à you will get 2155 items.
2
2477
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, location, price, color mode etc. So our database don?t include the images itself, just a path to the location of every image. Keywords -field have data for example like this: cat,animal,pet,home,child with pet,child. Now our search use Full-Text...
1
7122
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
2431
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 string arrays, which are just lists of people or companies in alphabetic order. These names may have accented and umlauted characters (which are present as the plain ASCII - not as the entity &# character). The page is UTF-8 encoded. e.g. ...
4
2171
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 help on this, Benny
1
2530
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 frameset if the "ALL" option is selected. Is there anyway to get the results to open in new windows? So if the user were to select the "ALL" option, is it possible to open 3 new windows with each result displaying? Here is my code:
13
5992
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 My search wants to use Containing text Thanks Preferred OS:Win2k3
4
2515
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, it will search for a particular file in the computer(searches entire drives).
13
2121
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 suggestions will be greatly appreciated. Jim #! /usr/bin/perl -w use strict;
0
9641
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10313
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.