Reply
ASP.NET User Registration
Old 07-25-2007, 05:01 PM ASP.NET User Registration
mb2000inc's Avatar
Skilled Talker

Posts: 51
Name: Mark
Location: Ohio
Hey,

So I have this great new project on my lap (for those of you who helped me out previously, your suggestions both rocked and worked tremendously...)

So, here's the new one.

I have a web form where a user registers and I have everything set in place, BUT, I'm trying to check the database and see if that particular user already exists...and I'm trying to include it in a giant bit of code already in place.

Essentially, what I would like to see is:

IF user exists then message box (you already exist) else create user profile.

But I don't have the verbage quite down.... so does anyone happen to have the code handy to do that?

As always, any input would be helpful.
__________________
EVERY DAY IS HALLOWEEN!
mb2000inc is offline
Reply With Quote
View Public Profile Visit mb2000inc's homepage!
 
When You Register, These Ads Go Away!
     
Old 07-26-2007, 10:08 AM Re: ASP.NET User Registration
mb2000inc's Avatar
Skilled Talker

Posts: 51
Name: Mark
Location: Ohio
I forgot to mention that this is my code:
Code:
Try
SQLCommand2.CommandText = "Select email from testtable where email = '" & txtEmail.Text & "'"
userRS = SQLCommand.ExecuteNonQuery()
IfNot userRS.EOF Then
bolEmailFound = True
userRS.close()
MessageBox("This <b>E-Mail Address</b> Currently Exists In Our Database.<br/> Please Check The E-mail Address And Try Again.")
SQLCommand.Connection = SqlDataSource1
Else
bolEmailFound = "false"
userRS.Close()
userRS = Nothing
EndIf
Else
'SQL INSERT Command and variables
SQLCommand.CommandText = "usp_testtable_Insert '" & txtFirst.Text & "','" & txtLast.Text & "','" & txtEmail.Text & "','" & txtUserID.Text & "','" & CStr(rblGender.SelectedValue) & "','" & rblZodiac.SelectedValue & "','" & rblLiving.SelectedValue & "','" & dlfollowup.SelectedValue & "','" & rblReferredBy.SelectedValue & "','" & txtOther.Text & "'"
SQLCommand.Connection = SqlDataSource1
SQLCommand.ExecuteNonQuery()
EndIf
Catch Ex As Exception
'If there are errors in any coding this will tell us where and what line number to look for
MessageBox("There was an error trying to run the query.<br />" + Ex.Message + "<br /><i>" + Ex.StackTrace + "</i>")
EndTry
SqlDataSource1.Close()

What am I missing?
__________________
EVERY DAY IS HALLOWEEN!

Last edited by mb2000inc : 07-26-2007 at 10:15 AM.
mb2000inc is offline
Reply With Quote
View Public Profile Visit mb2000inc's homepage!
 
Old 07-26-2007, 04:15 PM Re: ASP.NET User Registration
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,024
Name: Forrest Croce
Location: Seattle, WA
The first thing I see is a call to ExecuteNonQuery() against a select statement. That one call is probably breaking your whole page; this method never returns data from the db to the caller. There are three methods on a SQL command, which all send the SQL down to the database, but differ in terms of results. NonQuery is meant for delete, update, or insert statements, where you want to do work, but not get info. Scalar is when you only want a single value, say if you call Select @@Identity right after an insert. And then just regular Execute does the work at the db, and gives your program access to whatever data is sent back.

MessageBox ... that renders to client script, no? I haven't used this in ASPx myself, so I'm not familiar with that one.

Last thing I noticed; I don't know what type of object userRS is, but ADO.NET dropped the concept of record sets. You can work with DataTables, DataSets ( which are collections of DataTables that can have relationships ), and DataReaders. For a query that only returns one row, it's not going to matter very much which you use, but as far as I know, you aren't able to use recordset style coding anymore. I could be wrong.
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Reply     « Reply to ASP.NET User Registration
 

Thread Tools

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

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




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12916 seconds with 13 queries