473,473 Members | 4,257 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Table validating

Hey all,

If I need to just validate a single record against a table to see if it
exist, what's the best /fastest method to do this? shoud I create a table in
my dataset for such a task? this is an asp.net.vb app.
thanks,
rodchar
Nov 21 '05 #1
5 1039
Hi Rod,

I generally create a dataset/datatable and make a view of it, sort it on the
pk you're row provides; then use the find method. If it returns anything
except -1, it found the row. Sounds longer than you think - takes
miliseconds to execute.

HTH,

Bernie Yaeger

"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
Hey all,

If I need to just validate a single record against a table to see if it
exist, what's the best /fastest method to do this? shoud I create a table
in
my dataset for such a task? this is an asp.net.vb app.
thanks,
rodchar

Nov 21 '05 #2
i appreciate it.

"Bernie Yaeger" wrote:
Hi Rod,

I generally create a dataset/datatable and make a view of it, sort it on the
pk you're row provides; then use the find method. If it returns anything
except -1, it found the row. Sounds longer than you think - takes
miliseconds to execute.

HTH,

Bernie Yaeger

"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
Hey all,

If I need to just validate a single record against a table to see if it
exist, what's the best /fastest method to do this? shoud I create a table
in
my dataset for such a task? this is an asp.net.vb app.
thanks,
rodchar


Nov 21 '05 #3
rodchar,
In addition to Bernie's suggestion.

How big a table are you checking against?

If the table is not too large, I would create a DataTable out of it, define
a primary key, then use the Contains method.

Something like:

' define the table, only really need the primary keys
Dim table As New DataTable
table.Columns.Add("id", GetType(Integer))
table.PrimaryKey = New DataColumn() {table.Columns("id")}
' check to see if the row is in the table.
Dim key As Integer
If table.Rows.Contains(key) Then

End If

If you want to check the entire record, I would define all the fields as
keys. Contains is overloaded to accept a single value as above or an array
of values...

If the table is too large, I would use SQL do have the database itself check
for the record (with a SELECT statement or a Unique constraint).

Hope this helps
Jay

"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
Hey all,

If I need to just validate a single record against a table to see if it
exist, what's the best /fastest method to do this? shoud I create a table
in
my dataset for such a task? this is an asp.net.vb app.
thanks,
rodchar

Nov 21 '05 #4
Rodchar,

In addition to Jay, I would just go for his last suggestion and than read
it with an SQLCommand.executenonscalar using a where statement in the SQL
string.

Cor
Nov 21 '05 #5
Doh,

Executescalar of course.

http://msdn.microsoft.com/library/de...calartopic.asp

Sorry,

Cor
Nov 21 '05 #6

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

Similar topics

6
by: Alex Bink | last post by:
Hi, I have a validating event on a textbox in which I want to prevent the user to leave the textbox without entering the right data. Only if he clicks on another specific control he is allowed...
0
by: Joe | last post by:
Hi For a while now I have been finding postings of problems with the validating event not firing on controls properly. I too had this problem. The event would fire when clicking on another...
2
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating...
0
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls...
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
21
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on...
4
by: easoftware | last post by:
I am using VS .Net 2003 and VB. I have an app with one parent and two Mdi child forms. I need to validate data in the Mdi form. The Form.Validating event works when I try to close a Mdi form,...
6
by: Ryan | last post by:
I have a windows form that I want to force validation on controls (text boxes) when the user clicks a "Save" button. The only way I've found to do this is to cycle through every control and call...
16
by: Al Santino | last post by:
Hi, It appears displaying a messagebox in a validating event will cancel the subsequent event. In the program below, button 2's click event doesn't fire if you open a dialog box in button 1's...
3
by: TheSteph | last post by:
Hi Experts ! I have a Winform Program in C# / .NET 2.0 I would like to ensure that a value in a TextBox is a valid Int32 when user get out of it (TextBox loose focus)
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
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...
1
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.