Wrox Programmer Forums
|
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 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 October 16th, 2003, 10:58 PM
Authorized User
 
Join Date: Jun 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default ExecuteScalar


I'm using the following codes to see if the Name of the User that will be enter in a TextBox is a Valid Name in my Database Table.So far this codes are not working for me at the same time I'm not getting any errors but when I click the command button to return my Result I get the Error Message. Which mean no data was return or Found.

If strResult = "" Then ' it didnt return any rows
MsgBox("Error message!!")
Else
' it returned something
End If
This are the codes I'm using

Dim Result as String

If txtUser.Text = "" Then
MyDataAdapter.SelectCommand = New OLEDBConnection ()
MyDataAdapter.SelectCommand.Connection = MyConnection ()

MyDataAdapter.SelectCommand.CommandText = "Select UserID From UserTable WHERE UserID= '" & txtUser.Text & "'"

MyConnection.Open ()
Result = MyDataAdapter.SelectCommand.ExecuteScalar ()

Catch ex as Exception
Result = ""
MyConnection.Close

If Result = "" Then
MsgBox ("Error Message!!")
Else
MessageBox.Show (" User is Valid")

End If


What could be wrong with this codes. All I'm trying to do is make it work like a Log on. When any user uses a LogOn screen he first Enter his Name and then his Password once he clicks on the command button then it check if the User exists in the Database and then it check for the Password. I would like to check if the user Exists in the Database table.My Datatype for the Coulmn is Text. The Column the Name will be on is called UserID the table is called NewUser. The TextBox the Name is going to be enter is called txtUserID.
__________________
Thanks

Sincerely; Oscar Martinez
 
Old October 17th, 2003, 12:30 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

I am not sure whether this is the complete code, but take a look at this:
Code:
If txtUser.Text = "" Then 
MyDataAdapter.SelectCommand = New OLEDBConnection () 
MyDataAdapter.SelectCommand.Connection = MyConnection ()
Basically, this says: Query the User's details, when the txtUser text box is empty. The code will happily send an empty string to the database. However, there is probably no user in the database with an empty UserID, so no records are returned.

Does that make sense?

Imar



---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.









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