Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking 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 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 23rd, 2009, 09:40 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default How to Compare a TextBox Value to a SQL DataBase

Hi there i need to compare a textbox Value to a SQL databse i am lookinh for one column and once that is confiremed i need to look to the other column in the same row and bind it to a label control.

My DataBase hase 1 table with 2 columns

i have this so far
Code:
ProtectedSub CustomValidator_TextBox1_ServerValidate(ByVal source AsObject, _
ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) _
Handles CustomValidator_TextBox1.ServerValidate
args.IsValid = True
ForEach drv As DataRowView In SqlDataSource2.Select(DataSourceSelectArguments.Empty)
If drv("Alex").ToString() = args.Value Then
args.IsValid = False
ExitFor
EndIf
Next
If args.IsValid Then
Campaign.Text = ?????
EndIf
EndSub

Thanks
__________________
bx
 
Old January 27th, 2009, 11:49 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

This is interesting code since you say you need to compare a Textbox value to your database yet there is no reference to a textbox anywhere in your code?

I believe something like this would work for you (I am assuming based off of the code and explination you have provided):

vb Code:
For Each drv As DataRowView In SqlDataSource2.Select(DataSourceSelectArguments.Empty)
If Convert.ToString(drv("Alex").Equals(args.Value) Then
args.IsValid = False
Exit For
End If
'Assumption code
If Convert.ToString(drv("somecolumn").Equals(sometextbox) Then Campaign.Text = Convert.ToString(drv("somecolumn2"))
Next

FYI, there is a chance the code above, as written, has a bug in it. If the first if evaluates to true the For loop will exit before it evaluates the second If statement.

hth
-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."
===============================================





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to dump TextBox values to a database cJeffreywang BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 7 July 4th, 2007 12:43 AM
compare form field to database before submit chelle60 Javascript How-To 3 January 2nd, 2007 05:42 AM
compare these date fields and compare and get the susanring Oracle 1 July 24th, 2006 04:58 PM
Compare time in SQL JaJa SQL Language 2 October 21st, 2004 05:42 PM





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