all groups > sql server programming > march 2005 >
You're in the

sql server programming

group:

Let's do a SELECT statement for this and it is OK !


Let's do a SELECT statement for this and it is OK ! Marlon Brown
3/10/2005 11:37:22 PM
sql server programming:
I understand that store procedures are the recommended way to handle SQL
queries from an ASP application. However I am working on a small academic
assignment and I just need to get this over with. I created the store
procedure but now the teacher didn't accept that, as he is concerned he
would need to do additional work (install the store procedure in Query
Analyzer from his end for example).

Can you please clarify how I would accomplish the following using a Select
Statement (VB.NET, ASP.NET 2.0):



Dim myNextPage
myNextPage = "ConfirmInput.aspx"

Dim myString
myString = "SELECT Employee From Pubs " _
& "WHERE job_id = " & TxtBox1.Text And
& "WHERE employee_name = " & TxtBox2.Text And
& "WHERE hire_date = " & TxtBox3.Text

'Now I want to:
If (job_id = TxtBox1.Text) And (employee_name = TxtBox2.Text) And
(hire_date = TxtBox3.Text) Then 'I mean, if the secret answer the user typed
match the info in the SQL db, I can go ahead and reset the users password...

Response.Redirect("myNextPage")
'Then on Next page as soon as I have the info "didn't match" from SQL,
I will handle to display this on aspx.


Else
Response.Redirect("myNextPage")
'Display on next page Label.Text = "The phrase(s) you typed didn't
match. Please click back button and resubmit info."
'If possible, I would like to display all phrases that did not match
in 'myNextPage', so that user would know which ones he didn't answer
correctly.
'What's the best way to get his from such SQL query ?

End If

End Sub

Re: Let's do a SELECT statement for this and it is OK ! Marlon Brown
3/11/2005 12:08:49 AM
The issue I see is that when I type the below in my VB.NET bthDefault_Click,
the command "IF Exists (" is not recognized.

Partial Class Default_aspx

Sub btnDefault_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
If EXISTS ' < -- This doesn't seem to be a valid VB.NET
paramenter...
( ' <--- That is
[quoted text, click to view]

Re: Let's do a SELECT statement for this and it is OK ! Marlon Brown
3/11/2005 1:09:44 AM
Ah Ok, Got it now.
"Tibor Karaszi" <tibor_please.no.email_karaszi@hotmail.nomail.com> wrote in
message news:%23Zq94bhJFHA.656@TK2MSFTNGP14.phx.gbl...
[quoted text, click to view]

Re: Let's do a SELECT statement for this and it is OK ! Narayana Vyas Kondreddi
3/11/2005 7:53:56 AM
I am not sure you provided all the required info, but is the following of
any use?

IF EXISTS
(
SELECT 1
FROM Employee
WHERE job_id = <JobID>
AND employee_name = <EmpName>
AND hire_date = <HireDate>
AND SecretAnswer = <SecretAnswer>
)
BEGIN
UPDATE Employee
SET Password = <NewPassword>
WHERE job_id = <JobID>
AND employee_name = <EmpName>
AND hire_date = <HireDate>
AND SecretAnswer = <SecretAnswer>
END
ELSE
BEGIN
RAISERROR('Details not matched', 16, 1)
END

--
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/


[quoted text, click to view]

Re: Let's do a SELECT statement for this and it is OK ! Tibor Karaszi
3/11/2005 9:47:38 AM
Vyas posted the SQL statement, which you in turn need to surround by your VB code.

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/


[quoted text, click to view]

AddThis Social Bookmark Button