473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

need help fixing data retrieval

TG
Hi,

I am having a problem tryin to open the connection to a database the
nretreiving the informaiton based on the entry of an email address and
a password for authentication from the database. Here is my code, can
enyone help me out and fix it with the right peices?

Private Sub Submit1_ServerClick(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Submit1.ServerClick
Dim db As New BWMDB.Database(Session("Database"))
Dim cn
cn = db.Connection.ConnectionString.ToString()

Dim strSQL As String

strSQL = "SELECT * FROM BWM$Customer WHERE E-Mail = @E-Mail
AND Password = @Password"

Dim oCommand As New SqlCommand(strSQL, cn)
' Add parameters for the query.
oCommand.Parameters.Add("@E-Mail", Textfield1.Text.Trim())
oCommand.Parameters.Add("@Password", Textfield2.Text.Trim())
Dim dr As SqlDataReader
dr = db.GetDataReader(strSQL)

'dr = oCommand.ExecuteReader(System.Data.CommandBehavior .CloseConnection)

Try
If dr.HasRows Then
' The Email address and password match
' Set session variables
Me.Request.UrlReferrer.ToString()

Else
' Username and password DO NOT match

Response.Write("<script language=javascript>")
Response.Write("function alertUser()")
Response.Write("{alert('Email Address and Password do
not match our records')}")
Response.Write("</script")

End If
Catch ex As Exception
' Handle exceptions here
Label1.Text = "Could not retrieve the information: " &
ex.Message

Finally

dr.Close()
'db.Connection.Close()
cn.Close()
cn.Dispose()
oCommand.Dispose()
End Try
End Sub


Thanks
TG
Nov 21 '05 #1
2 1184
You definitely don't need Select *, and I'd use a If Exists construct. This
should help http://www.knowdotnet.com/articles/adoifexists.html
(But keep the parameters you're using - don't go the Dynamic Sql Route like
this example uses.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"TG" <tj*******@hotmail.com> wrote in message
news:48**************************@posting.google.c om...
Hi,

I am having a problem tryin to open the connection to a database the
nretreiving the informaiton based on the entry of an email address and
a password for authentication from the database. Here is my code, can
enyone help me out and fix it with the right peices?

Private Sub Submit1_ServerClick(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Submit1.ServerClick
Dim db As New BWMDB.Database(Session("Database"))
Dim cn
cn = db.Connection.ConnectionString.ToString()

Dim strSQL As String

strSQL = "SELECT * FROM BWM$Customer WHERE E-Mail = @E-Mail
AND Password = @Password"

Dim oCommand As New SqlCommand(strSQL, cn)
' Add parameters for the query.
oCommand.Parameters.Add("@E-Mail", Textfield1.Text.Trim())
oCommand.Parameters.Add("@Password", Textfield2.Text.Trim())
Dim dr As SqlDataReader
dr = db.GetDataReader(strSQL)

'dr = oCommand.ExecuteReader(System.Data.CommandBehavior .CloseConnection)
Try
If dr.HasRows Then
' The Email address and password match
' Set session variables
Me.Request.UrlReferrer.ToString()

Else
' Username and password DO NOT match

Response.Write("<script language=javascript>")
Response.Write("function alertUser()")
Response.Write("{alert('Email Address and Password do
not match our records')}")
Response.Write("</script")

End If
Catch ex As Exception
' Handle exceptions here
Label1.Text = "Could not retrieve the information: " &
ex.Message

Finally

dr.Close()
'db.Connection.Close()
cn.Close()
cn.Dispose()
oCommand.Dispose()
End Try
End Sub


Thanks
TG

Nov 21 '05 #2
TG

In addition to Bill, why do you not use dotNet code to show the alert.

Maybe you can use this sample I made once and sand to Dave

http://groups.google.com/groups?selm...TNGP14.phx.gbl

This was to show how a shared class can be used in ASPNET however you can
use that of course as well without that. But it is a nice sample as well how
to do use that shared class in my opinion.

I hope this helps?

Cor
Nov 21 '05 #3

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

Similar topics

9
by: J. Baute | last post by:
I'm caching data in the Application object to speed up certain pages on a website The main reason is that the retrieval of this data takes quite a while (a few seconds) and fetching the same data...
0
by: Redd | last post by:
The following is a technical report on a data modeling project that was recently assigned to me by my professor. I post it so that anyone else who is studying databases and data modeling can have...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
10
by: Doug Bell | last post by:
Hi, I have an application that has a "Data Access Class" and "User Interface Class". It is for receiving Purchase Order data from one system and pushing processed transactions to another...
3
by: GP | last post by:
We are connecting to sql server database in the webservices & retrieve the data as dataset from the webservices and load it to the aspx pages ,But we find loading of the aspx pages takes longer...
4
by: Hemant Shah | last post by:
Folks, I am having problem with an application that uses static SQL, the application basically browses through the table given start and end key most of the time it is processed from begining to...
5
by: Eric Layman | last post by:
Hi, Many years ago when I first learnt abt web dev in school, I was taught this methodology: <html> blah blabh
0
by: JosAH | last post by:
Greetings, Introduction At the end of the last Compiler article part I stated that I wanted to write about text processing. I had no idea what exactly to talk about; until my wife commanded...
26
by: Ravindra.B | last post by:
I have declared a global variable which is array of pointers and allocated memory for each array variable by using malloc. Some thing similar to below... static char *arr; main() { int i;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.