|
 |
aspx_beginners thread: I grobble at your feet for assistance
Message #1 by "Tim Farrell" <timothy.farrell@c...> on Tue, 6 Aug 2002 16:30:05
|
|
Sound desperate enough ;)
Here's my delema. I have a login form that I want to be able to pass on
UID form field in order to pull up some demographic data from the user on
the subsequent page. In this manner they will not need to input this
information on any forms they fillout.
So I know that I need to request the form field data from the login page
and that I need to be able to utilize the result of that request in order
to conduct a query to the employee database that will provide me the
demographic information. This will also allow me to personalize the site
for individual users.
Here is what I have so far. Can anyone examine this and suggest any
corrections?
Dim strUID As String
strUID = Request.Params( "UID" )
strSQL = "Select * FROM Employees where EmployeeID = & strUID"
Dim Cmd5 as New SQLCommand(strSQL,Conn)
Conn.Open()
fullnm.DataSource = Cmd5.ExecuteReader()
fullnm.DataBind()
Conn.Close()
This currently returns an error stating incorrect syntax near &.
Thank you for any help you may be able to provide.
Sincerely,
Tim
Message #2 by "Norman Beresford" <n.beresford@a...> on Tue, 6 Aug 2002 17:15:45 +0100
|
|
Hi Tim
Grovelling would be better ;)
Got your amphasand in the wrong place:
strSQL = "Select * FROM Employees where EmployeeID = & strUID"
should be
strSQL = "Select * FROM Employees where EmployeeID = "& strUID
HTH
Norman
Message #3 by "Tim Farrell" <timothy.farrell@c...> on Tue, 6 Aug 2002 17:32:07
|
|
> Hi Tim
Grovelling would be better ;)
Norman,
Indeed it would. I was thinking that at the least it would get your
attention, and I am glad it did.
I did in fact change the location of the ampersand to no avail. The error
message just reverts back to: Incorrect syntax near =
Is it me or does no one conduct this kind of operation anymore (form field
passing from one to many pages)?
Any other ideas?
Thanks for your time and your thoughts.
Sincerely,
Tim
Message #4 by Colin.Montgomery@C... on Tue, 6 Aug 2002 18:32:26 +0100
|
|
not sure about the .Net implications on this, but...
It seems you're declaring strUID as a String, and then using a SQL statement
which checks for Employees.EmployeeID being equal to that string - but i'm
assuming EmployeeID is an Integer in your DB?
If so, try this:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''
DIM intUID As Integer 'or maybe a Long or equivalent?
DIM strSQL As String
DIM Cmd5 as New SQLCommand(strSQL,Conn) 'maybe change the name of cmd5?
intUID = Request.Params( "UID" )
strSQL = "Select * FROM Employees where EmployeeID = " & intUID
Conn.Open()
fullnm.DataSource = Cmd5.ExecuteReader()
fullnm.DataBind()
Conn.Close()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''
HTH,
Col
-----Original Message-----
From: Tim Farrell [mailto:timothy.farrell@c...]
Sent: 06 August 2002 17:30
To: aspx_beginners
Subject: [aspx_beginners] I grobble at your feet for assistance
Sound desperate enough ;)
Here's my delema. I have a login form that I want to be able to pass on
UID form field in order to pull up some demographic data from the user on
the subsequent page. In this manner they will not need to input this
information on any forms they fillout.
So I know that I need to request the form field data from the login page
and that I need to be able to utilize the result of that request in order
to conduct a query to the employee database that will provide me the
demographic information. This will also allow me to personalize the site
for individual users.
Here is what I have so far. Can anyone examine this and suggest any
corrections?
Dim strUID As String
strUID = Request.Params( "UID" )
strSQL = "Select * FROM Employees where EmployeeID = & strUID"
Dim Cmd5 as New SQLCommand(strSQL,Conn)
Conn.Open()
fullnm.DataSource = Cmd5.ExecuteReader()
fullnm.DataBind()
Conn.Close()
This currently returns an error stating incorrect syntax near &.
Thank you for any help you may be able to provide.
Sincerely,
Tim
*******
This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not the
intended recipient, please telephone or email the sender and delete this message and any attachment from your system. If you are
not the intended recipient you must not copy this message or attachment or disclose the contents to any other person.
For further information about Clifford Chance please see our website at http://www.cliffordchance.com or refer to any Clifford
Chance office.
Message #5 by "Farrell, Timothy" <Timothy.Farrell@C...> on Tue, 6 Aug 2002 14:05:02 -0400
|
|
Colin,
Thanks for your thoughts. You're right, EmployeeID is an integer however,
the changes I made according to your suggestion did elliminate the error. I
still ge the syntax error indicating "Incorrect Syntax near =".
This error is referencing the following line:
strSQL = "Select * FROM Employees where EmployeeID = " & intUID
Basically what I am trying to do is pass form data from the login page to
the application form page to prepopulate form data redundant to the login
page and to query the db for additional data against the UID form value.
Further reading up on this indicates that I may be able to achieve this
through the use of Session state. If I were to place the following code on
the login page:
Session["UID"]=txtUID.Text
Response.Redirect("tef.aspx")
Then on the tef.aspx page put:
String strUID = Session["UID"].ToString();
And then retrieve the data filtered against value:
strSQL = "Select * FROM Employees where EmployeeID = " & strUID
Any thoughts on this or suggestions?
Thanks for your time Colin.
Sincerely,
Tim
-----Original Message-----
From: Colin.Montgomery@C...
[mailto:Colin.Montgomery@C...]
Sent: Tuesday, August 06, 2002 1:32 PM
To: aspx_beginners
Subject: [aspx_beginners] RE: I grobble at your feet for assistance
not sure about the .Net implications on this, but...
It seems you're declaring strUID as a String, and then using a SQL statement
which checks for Employees.EmployeeID being equal to that string - but i'm
assuming EmployeeID is an Integer in your DB?
If so, try this:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''
DIM intUID As Integer 'or maybe a Long or equivalent?
DIM strSQL As String
DIM Cmd5 as New SQLCommand(strSQL,Conn) 'maybe change the name of cmd5?
intUID = Request.Params( "UID" )
strSQL = "Select * FROM Employees where EmployeeID = " & intUID
Conn.Open()
fullnm.DataSource = Cmd5.ExecuteReader()
fullnm.DataBind()
Conn.Close()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''
HTH,
Col
The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.
Message #6 by Imar Spaanjaars <Imar@S...> on Tue, 06 Aug 2002 20:25:09 +0200
|
|
Hi Tim,
Have you written the contents of strSQL to the page or to the trace routines?
Since the code is technically correct, I am almost 100% sure, that strUID
does not contain a values, so effective you are passing
Select * FROM Employees where EmployeeID
to the database which indeed has a syntax error near
Examine the value of the SQL statement (debugging, response.writing, a
label, tracing, whatever) and check out whether there is a correct value or
not.
HtH
Imar
At 02:05 PM 8/6/2002 -0400, you wrote:
>Colin,
>
>Thanks for your thoughts. You're right, EmployeeID is an integer however,
>the changes I made according to your suggestion did elliminate the error. I
>still ge the syntax error indicating "Incorrect Syntax near =".
>
>This error is referencing the following line:
>strSQL = "Select * FROM Employees where EmployeeID = " & intUID
>
>Basically what I am trying to do is pass form data from the login page to
>the application form page to prepopulate form data redundant to the login
>page and to query the db for additional data against the UID form value.
>
>Further reading up on this indicates that I may be able to achieve this
>through the use of Session state. If I were to place the following code on
>the login page:
>
>Session["UID"]=txtUID.Text
>Response.Redirect("tef.aspx")
>
>Then on the tef.aspx page put:
>
>String strUID = Session["UID"].ToString();
>
>And then retrieve the data filtered against value:
>strSQL = "Select * FROM Employees where EmployeeID = " & strUID
>
>Any thoughts on this or suggestions?
>
>Thanks for your time Colin.
>
>Sincerely,
>Tim
Message #7 by "Tim Farrell" <timothy.farrell@c...> on Tue, 6 Aug 2002 19:45:47
|
|
Imar,
So are you saying that my request params statement is not receiving the
value from the UID object in my login form?
This could be the case because if I manually place in the value 99450 I
get a value.
Do you have an example of a script that you use or have used to pass form
values from one page to another?
Thanks Imar.
> Hi Tim,
Have you written the contents of strSQL to the page or to the trace
routines?
Since the code is technically correct, I am almost 100% sure, that strUID
does not contain a values, so effective you are passing
Select * FROM Employees where EmployeeID
to the database which indeed has a syntax error near
Examine the value of the SQL statement (debugging, response.writing, a
label, tracing, whatever) and check out whether there is a correct value
or
not.
HtH
Message #8 by Imar Spaanjaars <Imar@S...> on Tue, 06 Aug 2002 20:57:33 +0200
|
|
Hi Tim,
Passing form parameters from one aspx page to another is not as
straightforward as it was in previous versions of ASP. ASP.NET uses pages
that post to themselves instead of allowing you to set the "action"
attribute yourself.
At the following page a method is explained how you can refer to variables
from a form on a previous page.
http://www.aspalliance.com/kenc/passval.aspx
If this doesn't help, maybe you should explain a little what exactly and
how you are passing values to your page. W
HtH
Imar
At 07:45 PM 8/6/2002 +0000, you wrote:
>Imar,
>
>So are you saying that my request params statement is not receiving the
>value from the UID object in my login form?
>
>This could be the case because if I manually place in the value 99450 I
>get a value.
>
>Do you have an example of a script that you use or have used to pass form
>values from one page to another?
>
>Thanks Imar.
>
>
> > Hi Tim,
>
>Have you written the contents of strSQL to the page or to the trace
>routines?
>
>Since the code is technically correct, I am almost 100% sure, that strUID
>does not contain a values, so effective you are passing
>
> Select * FROM Employees where EmployeeID
>
>to the database which indeed has a syntax error near
>
>
>Examine the value of the SQL statement (debugging, response.writing, a
>label, tracing, whatever) and check out whether there is a correct value
>or
>not.
>
>HtH
Message #9 by "Satish Kumar" <satish_kumar123@h...> on Wed, 7 Aug 2002 13:12:58 +0530
|
|
Try this code..
Dim strUID As String
strUID = Request.Params( "UID" )
strSQL = "Select * FROM Employees where EmployeeID = "& strUID
Dim Cmd5 as New SQLCommand(strSQL,Conn)
Conn.Open()
fullnm.DataSource = Cmd5.ExecuteReader()
fullnm.DataBind()
Conn.Close()
Regards
satish.
----- Original Message -----
From: "Tim Farrell" <timothy.farrell@c...>
To: "aspx_beginners" <aspx_beginners@p...>
Sent: Tuesday, August 06, 2002 4:30 PM
Subject: [aspx_beginners] I grobble at your feet for assistance
> Sound desperate enough ;)
>
> Here's my delema. I have a login form that I want to be able to pass on
> UID form field in order to pull up some demographic data from the user on
> the subsequent page. In this manner they will not need to input this
> information on any forms they fillout.
>
> So I know that I need to request the form field data from the login page
> and that I need to be able to utilize the result of that request in order
> to conduct a query to the employee database that will provide me the
> demographic information. This will also allow me to personalize the site
> for individual users.
>
> Here is what I have so far. Can anyone examine this and suggest any
> corrections?
>
> Dim strUID As String
> strUID = Request.Params( "UID" )
> strSQL = "Select * FROM Employees where EmployeeID = & strUID"
> Dim Cmd5 as New SQLCommand(strSQL,Conn)
> Conn.Open()
> fullnm.DataSource = Cmd5.ExecuteReader()
> fullnm.DataBind()
> Conn.Close()
>
> This currently returns an error stating incorrect syntax near &.
>
> Thank you for any help you may be able to provide.
>
> Sincerely,
>
> Tim
>
Message #10 by "Royce Fickling" <rfickling@d...> on Thu, 8 Aug 2002 00:47:09
|
|
> Sound desperate enough ;)
> Here's my delema. I have a login form that I want to be able to pass on
U> ID form field in order to pull up some demographic data from the user
on
t> he subsequent page. In this manner they will not need to input this
i> nformation on any forms they fillout.
> So I know that I need to request the form field data from the login page
a> nd that I need to be able to utilize the result of that request in
order
t> o conduct a query to the employee database that will provide me the
d> emographic information. This will also allow me to personalize the
site
f> or individual users.
> Here is what I have so far. Can anyone examine this and suggest any
c> orrections?
> Dim strUID As String
> strUID = Request.Params( "UID" )
> strSQL = "Select * FROM Employees where EmployeeID = & strUID"
> Dim Cmd5 as New SQLCommand(strSQL,Conn)
> Conn.Open()
> fullnm.DataSource = Cmd5.ExecuteReader()
> fullnm.DataBind()
> Conn.Close()
> This currently returns an error stating incorrect syntax near &.
> Thank you for any help you may be able to provide.
> Sincerely,
> Tim
Hi Tim,
Doesn't a string embedded in a SQL statement have to be enclosed in
quotes? Something like
strSQL = "Select * FROM Employees where EmployeeID = 'strUID'"
I knonw that if I were coding the same thing in C++, this is what I would
do.
Good luck,
Royce
Message #11 by rod@s... on Thu, 8 Aug 2002 09:04:23 +0800
|
|
Tim,
Not sure about passing the login info but I believe that the last strSQL
suggestion should be:
strSQL = "Select * FROM Employees where EmployeeID = " & strUID
Not:
strSQL = "Select * FROM Employees where EmployeeID = & strUID"
To concatinate the variable to the string.
If the variable (strUID) is a string as Royce felt then it would be:
strSQL = "Select * FROM Employees where EmployeeID = '" & strUID &"'"
to enclose it in single quotes.
Rod
Message #12 by "Tim Farrell" <timothy.farrell@c...> on Thu, 8 Aug 2002 15:42:34
|
|
Imar,
Thank you for the link. It helped alot. The problem I am faced with is
combining db query to the employees table and obtaining the results of the
form in the get function. In other words, if I just build the page to
verify that the user exists and their credentials are accurate, then all
is fine. As soon as I incorporate script to save the UID value in cache
to pass along to the next page I get errors. On the other hand, if I
create a page that allows me to enter in username and password on a form
not linked to a db and save the values in cache, I can retrieve them on
the next page no problem.
Do you know how I can encompass both of these functions (db query and
field cache) in script without error.
Here is what I am trying to achieve:
1.user fills out login form fields
2.fields are verified against user db
3.uid field is retained in cache for latter use in subsequent queries.
4.uid is retrieved in susbsequent pages for retrieval of user info and
personalization.
Here is the code for login page:
<%@ Import NameSpace="System.Data.SqlClient"%>
<%@ Import NameSpace="System.Data"%>
<%@ Page Language="vb" ClassName="LoginClass"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Login</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body leftmargin="0" topmargin="30">
<script runat="server" language="vb">
Sub Page_Load
Dim strLinkPath As String
If not IsPostBack Then
strLinkPath = String.Format( "Register.aspx?ReturnUrl={0}",
Request.Params( "ReturnUrl" ) )
lnkRegister.NavigateUrl = String.Format( strLinkPath )
End If
End Sub
Sub Button_Click( s As Object, e As EventArgs )
If IsValid Then
If DbAuthenticate( EmployeeID.Text, Password.Text ) > 0 Then
FormsAuthentication.RedirectFromLoginPage(
EmployeeID.Text, False )
End If
End If
Server.Transfer("default.aspx")
End Sub
Function DBAuthenticate( strEmployeeID As String, strPassword As
String ) As Integer
Dim conMyData As SqlConnection
Dim cmdSelect As SqlCommand
Dim parmReturnValue As SqlParameter
Dim intResult As Integer
conMyData = New SqlConnection
( "server=ntphoenix;uid=******;pwd=******;database=****" )
cmdSelect = New SqlCommand( "DBAuthenticate", conMyData )
cmdSelect.CommandType = CommandType.StoredProcedure
parmReturnValue = cmdSelect.Parameters.Add( "Return_Value",
SqlDbType.Int )
ParmReturnValue.Direction = ParameterDirection.ReturnValue
cmdSelect.Parameters.Add( "@EmployeeID", strEmployeeID )
cmdSelect.Parameters.Add( "@Password", strPassword )
conMyData.Open()
cmdSelect.ExecuteNonQuery()
intResult = cmdSelect.Parameters( "Return_Value" ).Value
conMyData.Close()
If intResult < 0 Then
If intResult = -1 Then
lblMessage.Text = "The EmployeeID Entered is not
Registered!"
Else
lblMessage.Text = "You have entered an invalid password!"
End If
End If
Return intResult
End Function
</script>
<script runat="server">
Public ReadOnly Property EmployeeID() As String
Get
Return EmployeeID.text
End Get
End Property
</script>
<form runat="server">
<!--#include file="Styles.css" -->
<div align="center">
<table cellpadding="0" cellspacing="0"
border="0" bordercolor="Gainsboro" bordercolordark="DarkBlue">
<tr>
<td colspan="2"
width="400" align="middle"><IMG src="images/login.gif"></td>
</tr>
<tr>
<td colspan="2">
<asp:Label
ID="lblMessage" ForeColor="red" Font-Bold="True" Runat="server" />
</td>
</tr>
<tr class="tabletext"
bgcolor="AliceBlue">
<td>Employee UID:</td>
<td>
<asp:TextBox
id="EmployeeID" runat="server" />
<asp:RequiredFieldValidator ControlToValidate="EmployeeID"
Text="Required!" Runat="server" />
</td>
</tr>
<tr class="tabletext"
bgcolor="AliceBlue">
<td>Password:</td>
<td>
<asp:TextBox
id="Password" runat="server" TextMode="Password" />
<asp:RequiredFieldValidator ControlToValidate="Password"
Text="Required!" Runat="server" />
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2">
<asp:Button
Text="Login" OnClick="Button_Click" RunAt="server" />
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr class="tabletext"
bgcolor="PapayaWhip">
<td colspan="2">
<asp:HyperLink
ID="lnkRegister" Runat="server" />
</td>
</tr>
</table>
</div>
</form>
</body>
</HTML>
**********************************
The error I am getting is:
'EmployeeID' is already declared as 'Protected Dim EmployeeID As
System.Web.UI.WebControls.TextBox' in this class.
I can't seem to get past this.
Thank you for your thoughts.
Tim
Message #13 by Imar@S... on Thu, 8 Aug 2002 21:22:42
|
|
Hi Tim,
From a quick scan of your code, it seems that all troubles are caused by
the fact that you are redeclaring a variable name.
It seems that you have both a Textbox called EmployeedID and a property
called EmployeeID. The compiler doesn't know when you are referring to
one or to the other.
Proper Hungarian notation might have avoid this problem. To avoid this
problem, use uniqe names, or use a short prefix on all your variables,
like txtEmployeeID for a textbox, iEmployeeID for the variable you are
passing to a SQL statement, and EmployeeID as the name for a public
property.
HtH
Imar
> Imar,
> Thank you for the link. It helped alot. The problem I am faced with
is
c> ombining db query to the employees table and obtaining the results of
the
f> orm in the get function. In other words, if I just build the page to
v> erify that the user exists and their credentials are accurate, then
all
i> s fine. As soon as I incorporate script to save the UID value in
cache
t> o pass along to the next page I get errors. On the other hand, if I
c> reate a page that allows me to enter in username and password on a
form
n> ot linked to a db and save the values in cache, I can retrieve them on
t> he next page no problem.
> Do you know how I can encompass both of these functions (db query and
f> ield cache) in script without error.
> Here is what I am trying to achieve:
1> .user fills out login form fields
2> .fields are verified against user db
3> .uid field is retained in cache for latter use in subsequent queries.
4> .uid is retrieved in susbsequent pages for retrieval of user info and
p> ersonalization.
> Here is the code for login page:
<> %@ Import NameSpace="System.Data.SqlClient"%>
<> %@ Import NameSpace="System.Data"%>
<> %@ Page Language="vb" ClassName="LoginClass"%>
<> !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<> HTML>
<> HEAD>
<> title>Login</title>
<> meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<> meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<> meta name="vs_defaultClientScript" content="JavaScript">
<> meta name="vs_targetSchema"
c> ontent="http://schemas.microsoft.com/intellisense/ie5">
<> /HEAD>
<> body leftmargin="0" topmargin="30">
>
> <script runat="server" language="vb">
> Sub Page_Load
> Dim strLinkPath As String
>
> If not IsPostBack Then
> strLinkPath = String.Format( "Register.aspx?ReturnUrl
{0}",
R> equest.Params( "ReturnUrl" ) )
> lnkRegister.NavigateUrl = String.Format( strLinkPath )
> End If
> End Sub
>
> Sub Button_Click( s As Object, e As EventArgs )
> If IsValid Then
> If DbAuthenticate( EmployeeID.Text, Password.Text ) > 0
Then
> FormsAuthentication.RedirectFromLoginPage(
E> mployeeID.Text, False )
> End If
> End If
> Server.Transfer("default.aspx")
> End Sub
>
> Function DBAuthenticate( strEmployeeID As String, strPassword
As
S> tring ) As Integer
> Dim conMyData As SqlConnection
> Dim cmdSelect As SqlCommand
> Dim parmReturnValue As SqlParameter
> Dim intResult As Integer
>
> conMyData = New SqlConnection
(> "server=ntphoenix;uid=******;pwd=******;database=****" )
> cmdSelect = New SqlCommand( "DBAuthenticate", conMyData )
> cmdSelect.CommandType = CommandType.StoredProcedure
> parmReturnValue = cmdSelect.Parameters.Add( "Return_Value",
S> qlDbType.Int )
> ParmReturnValue.Direction = ParameterDirection.ReturnValue
> cmdSelect.Parameters.Add( "@EmployeeID", strEmployeeID )
> cmdSelect.Parameters.Add( "@Password", strPassword )
> conMyData.Open()
> cmdSelect.ExecuteNonQuery()
> intResult = cmdSelect.Parameters( "Return_Value" ).Value
> conMyData.Close()
> If intResult < 0 Then
> If intResult = -1 Then
> lblMessage.Text = "The EmployeeID Entered is not
R> egistered!"
> Else
> lblMessage.Text = "You have entered an invalid
password!"
> End If
> End If
> Return intResult
> End Function
> </script>
> <script runat="server">
> Public ReadOnly Property EmployeeID() As String
> Get
> Return EmployeeID.text
> End Get
> End Property
> </script>
> <form runat="server">
> <!--#include file="Styles.css" -->
> <div align="center">
> <table cellpadding="0" cellspacing="0"
b> order="0" bordercolor="Gainsboro" bordercolordark="DarkBlue">
> <tr>
> <td colspan="2"
w> idth="400" align="middle"><IMG src="images/login.gif"></td>
> </tr>
> <tr>
> <td colspan="2">
> <asp:Label
I> D="lblMessage" ForeColor="red" Font-Bold="True" Runat="server" />
> </td>
> </tr>
> <tr class="tabletext"
b> gcolor="AliceBlue">
> <td>Employee UID:</td>
> <td>
> <asp:TextBox
i> d="EmployeeID" runat="server" />
>
> <asp:RequiredFieldValidator ControlToValidate="EmployeeID"
T> ext="Required!" Runat="server" />
> </td>
> </tr>
> <tr class="tabletext"
b> gcolor="AliceBlue">
> <td>Password:</td>
> <td>
> <asp:TextBox
i> d="Password" runat="server" TextMode="Password" />
>
> <asp:RequiredFieldValidator ControlToValidate="Password"
T> ext="Required!" Runat="server" />
> </td>
> </tr>
> <tr>
> <td
colspan="2"> </td>
> </tr>
> <tr>
> <td colspan="2">
> <asp:Button
T> ext="Login" OnClick="Button_Click" RunAt="server" />
> </td>
> </tr>
> <tr>
> <td
colspan="2"> </td>
> </tr>
> <tr class="tabletext"
b> gcolor="PapayaWhip">
> <td colspan="2">
> <asp:HyperLink
I> D="lnkRegister" Runat="server" />
> </td>
> </tr>
> </table>
> </div>
> </form>
> </body>
<> /HTML>
> **********************************
T> he error I am getting is:
'> EmployeeID' is already declared as 'Protected Dim EmployeeID As
S> ystem.Web.UI.WebControls.TextBox' in this class.
> I can't seem to get past this.
> Thank you for your thoughts.
T> im
>
Message #14 by "Farrell, Timothy" <Timothy.Farrell@C...> on Mon, 12 Aug 2002 16:21:14 -0400
|
|
Imar,
Thank you for being patient with me, I'm still just learning .net but I feel
that I am learning much more with your help and suggestions.
Ok, so I have made the changes you recommended and have been able to bypass
the before mentioned error. Thank you.
Currently though, I am getting the following error instead:
System.InvalidCastException: Specified cast is not valid
The error references my get method in order to retrieve the value from the
form:
Sub Page_Load()
If Not IsPostBack Then
-> lg = CType(Context.Handler, LoginClass) <-
End IF
End Sub
This method was acquired from the following article:
ms-help://MS.NETFrameworkSDK/cpguidenf/html/cpconpassingservercontrolvaluesb
etweenpages.htm
Can you comment on the nature of this error? I could seem to locate an
explanation on MSDN Knowledgebase.
Thank you sincerely,
Tim
-----Original Message-----
From: Imar@S... [mailto:Imar@S...]
Sent: Thursday, August 08, 2002 5:23 PM
To: aspx_beginners
Subject: [aspx_beginners] RE: I grobble at your feet for assistance
Hi Tim,
From a quick scan of your code, it seems that all troubles are caused by
the fact that you are redeclaring a variable name.
It seems that you have both a Textbox called EmployeedID and a property
called EmployeeID. The compiler doesn't know when you are referring to
one or to the other.
Proper Hungarian notation might have avoid this problem. To avoid this
problem, use uniqe names, or use a short prefix on all your variables,
like txtEmployeeID for a textbox, iEmployeeID for the variable you are
passing to a SQL statement, and EmployeeID as the name for a public
property.
HtH
Imar
> Imar,
> Thank you for the link. It helped alot. The problem I am faced with
is
c> ombining db query to the employees table and obtaining the results of
the
f> orm in the get function. In other words, if I just build the page to
v> erify that the user exists and their credentials are accurate, then
all
i> s fine. As soon as I incorporate script to save the UID value in
cache
t> o pass along to the next page I get errors. On the other hand, if I
c> reate a page that allows me to enter in username and password on a
form
n> ot linked to a db and save the values in cache, I can retrieve them on
t> he next page no problem.
> Do you know how I can encompass both of these functions (db query and
f> ield cache) in script without error.
> Here is what I am trying to achieve:
1> .user fills out login form fields
2> .fields are verified against user db
3> .uid field is retained in cache for latter use in subsequent queries.
4> .uid is retrieved in susbsequent pages for retrieval of user info and
p> ersonalization.
> Here is the code for login page:
<> %@ Import NameSpace="System.Data.SqlClient"%>
<> %@ Import NameSpace="System.Data"%>
<> %@ Page Language="vb" ClassName="LoginClass"%>
<> !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<> HTML>
<> HEAD>
<> title>Login</title>
<> meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<> meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<> meta name="vs_defaultClientScript" content="JavaScript">
<> meta name="vs_targetSchema"
c> ontent="http://schemas.microsoft.com/intellisense/ie5">
<> /HEAD>
<> body leftmargin="0" topmargin="30">
>
> <script runat="server" language="vb">
> Sub Page_Load
> Dim strLinkPath As String
>
> If not IsPostBack Then
> strLinkPath = String.Format( "Register.aspx?ReturnUrl
{0}",
R> equest.Params( "ReturnUrl" ) )
> lnkRegister.NavigateUrl = String.Format( strLinkPath )
> End If
> End Sub
>
> Sub Button_Click( s As Object, e As EventArgs )
> If IsValid Then
> If DbAuthenticate( EmployeeID.Text, Password.Text ) > 0
Then
> FormsAuthentication.RedirectFromLoginPage(
E> mployeeID.Text, False )
> End If
> End If
> Server.Transfer("default.aspx")
> End Sub
>
> Function DBAuthenticate( strEmployeeID As String, strPassword
As
S> tring ) As Integer
> Dim conMyData As SqlConnection
> Dim cmdSelect As SqlCommand
> Dim parmReturnValue As SqlParameter
> Dim intResult As Integer
>
> conMyData = New SqlConnection
(> "server=ntphoenix;uid=******;pwd=******;database=****" )
> cmdSelect = New SqlCommand( "DBAuthenticate", conMyData )
> cmdSelect.CommandType = CommandType.StoredProcedure
> parmReturnValue = cmdSelect.Parameters.Add( "Return_Value",
S> qlDbType.Int )
> ParmReturnValue.Direction = ParameterDirection.ReturnValue
> cmdSelect.Parameters.Add( "@EmployeeID", strEmployeeID )
> cmdSelect.Parameters.Add( "@Password", strPassword )
> conMyData.Open()
> cmdSelect.ExecuteNonQuery()
> intResult = cmdSelect.Parameters( "Return_Value" ).Value
> conMyData.Close()
> If intResult < 0 Then
> If intResult = -1 Then
> lblMessage.Text = "The EmployeeID Entered is not
R> egistered!"
> Else
> lblMessage.Text = "You have entered an invalid
password!"
> End If
> End If
> Return intResult
> End Function
> </script>
> <script runat="server">
> Public ReadOnly Property EmployeeID() As String
> Get
> Return EmployeeID.text
> End Get
> End Property
> </script>
> <form runat="server">
> <!--#include file="Styles.css" -->
> <div align="center">
> <table cellpadding="0" cellspacing="0"
b> order="0" bordercolor="Gainsboro" bordercolordark="DarkBlue">
> <tr>
> <td colspan="2"
w> idth="400" align="middle"><IMG src="images/login.gif"></td>
> </tr>
> <tr>
> <td colspan="2">
> <asp:Label
I> D="lblMessage" ForeColor="red" Font-Bold="True" Runat="server" />
> </td>
> </tr>
> <tr class="tabletext"
b> gcolor="AliceBlue">
> <td>Employee UID:</td>
> <td>
> <asp:TextBox
i> d="EmployeeID" runat="server" />
>
> <asp:RequiredFieldValidator ControlToValidate="EmployeeID"
T> ext="Required!" Runat="server" />
> </td>
> </tr>
> <tr class="tabletext"
b> gcolor="AliceBlue">
> <td>Password:</td>
> <td>
> <asp:TextBox
i> d="Password" runat="server" TextMode="Password" />
>
> <asp:RequiredFieldValidator ControlToValidate="Password"
T> ext="Required!" Runat="server" />
> </td>
> </tr>
> <tr>
> <td
colspan="2"> </td>
> </tr>
> <tr>
> <td colspan="2">
> <asp:Button
T> ext="Login" OnClick="Button_Click" RunAt="server" />
> </td>
> </tr>
> <tr>
> <td
colspan="2"> </td>
> </tr>
> <tr class="tabletext"
b> gcolor="PapayaWhip">
> <td colspan="2">
> <asp:HyperLink
I> D="lnkRegister" Runat="server" />
> </td>
> </tr>
> </table>
> </div>
> </form>
> </body>
<> /HTML>
> **********************************
T> he error I am getting is:
'> EmployeeID' is already declared as 'Protected Dim EmployeeID As
S> ystem.Web.UI.WebControls.TextBox' in this class.
> I can't seem to get past this.
> Thank you for your thoughts.
T> im
>
The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.
Message #15 by Imar Spaanjaars <Imar@S...> on Mon, 12 Aug 2002 23:12:36 +0200
|
|
Hi Tim,
I have no idea what's causing the error, as you haven't posted the complete
code. The lines you posted look correct, though. But how did you declare
lg? Did you declare it as lg or lc (LoginClass ??) Did you declare it as
type LoginClass. Is the page you are creating really using a page directive
ClassName="LoginClass"?
Also, I still think you may be getting yourself in the troubles of using
variables from a previous page, just to avoid something that doesn't work,
or that you don't understand completely.
Is it really necessary to use this two page approach?
How about you post some more code about the app you're building and
describe what it is supposed to do. Maybe stuff can be way easier than it
looks.
If it's all too much to post here, you could send me a zip fie with the
relevant code (but please cut as much as possible irrelevant stuff, like
simple controls, CSS and table layout, so it's easier to focus on what
you're trying to accomplish).
HtH
Imar
At 04:21 PM 8/12/2002 -0400, you wrote:
>Imar,
>
>Thank you for being patient with me, I'm still just learning .net but I feel
>that I am learning much more with your help and suggestions.
>
>Ok, so I have made the changes you recommended and have been able to bypass
>the before mentioned error. Thank you.
>
>Currently though, I am getting the following error instead:
>System.InvalidCastException: Specified cast is not valid
>
>The error references my get method in order to retrieve the value from the
>form:
>Sub Page_Load()
> If Not IsPostBack Then
> -> lg = CType(Context.Handler, LoginClass) <-
> End IF
>End Sub
>
>This method was acquired from the following article:
>ms-help://MS.NETFrameworkSDK/cpguidenf/html/cpconpassingservercontrolvaluesb
>etweenpages.htm
>
>Can you comment on the nature of this error? I could seem to locate an
>explanation on MSDN Knowledgebase.
>
>Thank you sincerely,
>
>Tim
|
|
 |