Hi everyone,
I am writing a simple login application in asp 2.0. I have spent quite a little bit of time of this error so any help would be greatly appreciated.
Here is the code i am using.
Dim cnAs SqlConnectionDim cmdAs SqlCommand
Dim sqlAsString ="select password from attendant where " & _
" ((username = @.username) and (password = @.password)"
cn =
New SqlConnection("Data Source=z-davis\sqlexpress;Initial Catalog=Trainingdb;Integrated Security=True")' cn = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("TrainingdbConnectionString").ToString)'I have tried both connection strings and get the same error.
cmd =New SqlCommand(sql, cn)
cmd.Parameters.Add(
"@.username", SqlDbType.VarChar, 50)cmd.Parameters(
"@.username").Value = txtuser.Textcmd.Parameters.Add(
"@.password", SqlDbType.VarChar, 50)cmd.Parameters(
"@.password").Value = txtpass.Textcn.Open()
Dim myreaderAs SqlDataReadermyreader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
'The line above is where i get the error.
If myreader.Read()ThenFormsAuthentication.RedirectFromLoginPage(txtuser.Text,
False)ElseResponse.Write(
"Try again")After stepping through the code the error stops on this line:
myreader = cmd.executereader(commandbehavior.closeconnection)
The error that is generated is: Incorrect syntax near ')'
Any help would be greatly appreciated or any other code snippets
Thanks,
notrosh
In this line you have 3 open parentheses and only 2 close parentheses.Dim sqlAsString ="select password from attendant where " & _
" ((username = @.username) and (password = @.password)"
Remove the first open parenthesis and you will have better luck.
Thanks,
Sometimes you need an outside eye to see an error that simple.
zach davis
|||Or you need to have made that same sort of error a few dozen timesI've learrned to count my parentheses using my fingers. Working left to right in my SQL statement, I put up a finger each time I open one, and put down a finger each time I close one. When I get to the last character, if I have any fingers sticking up, I know I have a problem. Pretty silly approach, but it works for me.
No comments:
Post a Comment