Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 30th, 2008, 08:42 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Location: london, , United Kingdom.
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default How to check values in a Sql DataBase

Hi there i have a textbox controll in a web form a next btn and a label controll, on btn click event i want to open the connection to the db look for textbox value then if record exists lbl.text="record exsist, try onother"
else
Response.ridirect=Default.aspx

I need help whith the searching of the db and i am using VB

thanks for looking
__________________
bx
  #2 (permalink)  
Old December 30th, 2008, 08:53 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Hello. You need help in building the sql??? You will have to provide more info them, i
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
  #3 (permalink)  
Old December 30th, 2008, 09:30 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Yes it is not entirely clear as to what you are asking. Are you asking how to connect to the database so that you can preform the search or are you asking how to search a database?

-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
  #4 (permalink)  
Old December 30th, 2008, 10:00 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Location: london, , United Kingdom.
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

I am asking how to search the database
__________________
bx
  #5 (permalink)  
Old December 30th, 2008, 10:13 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

First, what RDBMS are you using?

The next obvious question, then, is how do you want to search the database? Are you searching a single table or do you want to query against multiple tables? In the same vein are you searching a single column or multiple columns?

Are you looking for an exact match in the database or for rows of data that are similar to whatever was entered into the textbox? For example if someone types 'mo' into the textbox rows of data will be returned where the strin 'mo' is found as well as rows where 'mom', 'moth', and so forth will be returned as well.

Are you wanting to do a phonetic ("sounds like") search where rows of data are returned if they contain words that sound like those placed in the textbox?

-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
  #6 (permalink)  
Old December 30th, 2008, 01:22 PM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Location: london, , United Kingdom.
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

I am using MS SQL 2005 and i need to search 1 tabe and multiple columns

so the idea is to search the database for whatever is entered into the textbox and tell me if any thing was found in the db like you sed 'mom', 'moth',

i am not wanting to do a phonetic

thanks
__________________
bx
  #7 (permalink)  
Old December 30th, 2008, 01:36 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

If you want a fast and dirty solution, something like the following would work*:

csharp Code:
string SearchText = textbox1.Text;
 string Sql = @"SELECT * from MyTable where Column1 like '%"
                     SearchText + "%' OR Column2 like '%" +
                     SearchText + "%' OR Column3 like '%" +
                     SearchText + "%'";

Personally I would use a Full Text Index when trying to search a database since it allows for flexibility if and when I would need to search more columns/tables as well as various other things. The dynamic sql approach I showed above is effective only for the most trivial of database searches.

Information about Full Text Indexs can be found at the following links:

http://www.wherecanibuyit.co.uk/ASP/...xt-search.html

http://www.simple-talk.com/sql/learn...uage-features/

hth
-Doug.

##EDIT##
It is probably worthwhile for me to point out the use of the wildcard character %. By wrapping your search critera with % % your search will look for the existence of the string ANYWHERE within a given word. So a search for 'po' would return pop, empower, and expo. More information about SQL Server wildcard characters can be found here:

http://doc.ddart.net/mssql/sql70/la-lz_2.htm
##/EDIT##

*I am using dynamic sql here for demonstration only. You should move this to a sproc or to some other form of dynamic sql that is better protected (e.g. parametrized) from SQL Injection
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================

Last edited by dparsons; December 30th, 2008 at 01:43 PM.. Reason: Wildcard Explination
  #8 (permalink)  
Old December 30th, 2008, 02:50 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
Originally Posted by bex View Post
Hi there i have a textbox controll in a web form a next btn and a label controll, on btn click event i want to open the connection to the db look for textbox value then if record exists lbl.text="record exsist, try onother"
I just put a quick example of how to do this on my blog, using server-side validation with a CustomValidator:

http://leedumond.com/blog/how-to-val...om-a-database/

The example shows a straight equality check, but obviously you can do more complex comparisons as well, including regular expressions.

The example is C# but should not be difficult to convert. If you need a VB version, please let me know.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}

Last edited by Lee Dumond; December 30th, 2008 at 02:54 PM..
  #9 (permalink)  
Old December 30th, 2008, 02:56 PM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Location: london, , United Kingdom.
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

i do need the VB version please
__________________
bx
  #10 (permalink)  
Old December 30th, 2008, 03:26 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
Originally Posted by bex View Post
i do need the VB version please
Code:
Protected Sub custval_txtTeam_ServerValidate(ByVal source As Object, _
       ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) _
       Handles custval_txtTeam.ServerValidate

        args.IsValid = True

        For Each drv As DataRowView In SqlDataSourceTeams.Select(DataSourceSelectArguments.Empty)
            If drv("TeamName").ToString() = args.Value Then
                args.IsValid = False
                Exit For
            End If
        Next

        If args.IsValid Then
            lblResult.Text = "Congratulations! That name is not taken."
        End If

    End Sub
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
code to check values in two columns?? Mazzy Excel VBA 2 December 13th, 2007 07:39 AM
Check for items with low values adias SQL Language 0 May 5th, 2006 02:01 PM
Check values Dj Kat MySQL 2 March 23rd, 2006 04:10 AM
how can i check for duplicate values before saving noor ASP.NET 1.0 and 1.1 Basics 3 June 10th, 2005 09:28 AM
help me to pass the check box values to new page ansar BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 November 16th, 2004 06:08 AM



All times are GMT -4. The time now is 10:33 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.