By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,032 Members | 1,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,032 IT Pros & Developers. It's quick & easy.

need help fixing data retrieval

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.