|
 |
asp_databases thread: Finding record in database w/ ASP
Message #1 by "Cynthia Halim" <cynthiahalim@h...> on Wed, 28 Feb 2001 12:24:11
|
|
Hi,
I have been trying to find a record in the database from a user's input,
if the data is the same as the one in the database record, it will display
the record from the database. However, if the input is not the same as the
one in the record, it will keep looping until the EOF then display "no
record". I did the code below but it still doesnt work
Please tell me what is wrong with this code and help me to solve the
problem.
Thank you for your help!!
yours sincerely, cynthia
<%
varStudentID=Request.Form("StudentNo")
Dim oRSd
Set oRSd=Server.CreateObject("ADODB.Recordset")
sqltext="SELECT * FROM StuGrp "
sqltext=sqltext & " WHERE StudentID='" & varStudentID & "';"
oRSd.Open sqltext, "DSN=openday"
Response.Write "<TABLE BORDER=1>"
Do While Not oRSd.EOF
If varStudentID=oRSd("StudentNo") then
Response.Write "<TR><TD>" & oRSd("StudentID") & "</TD>"
Response.Write "<TD>" & oRSd("StudentName") & "</TD>"
Response.Write "<TD>" & oRSd("GroupID") & "</TD></TR>"
oRSd.MoveNext
End if
Loop
Response.Write "no record"
'Response.Write "</TABLE>"
%>
Message #2 by "Vincent Drabbe" <vincent@w...> on Wed, 28 Feb 2001 13:38:45 +0100
|
|
You should first check if the oRSd is empty, then display "Table empty" else
loop through the oRSd
----- Original Message -----
From: "Cynthia Halim" <cynthiahalim@h...>
To: "ASP Databases" <asp_databases@p...>
Sent: Wednesday, February 28, 2001 12:24 PM
Subject: [asp_databases] Finding record in database w/ ASP
> Hi,
>
> I have been trying to find a record in the database from a user's input,
> if the data is the same as the one in the database record, it will display
> the record from the database. However, if the input is not the same as the
> one in the record, it will keep looping until the EOF then display "no
> record". I did the code below but it still doesnt work
> Please tell me what is wrong with this code and help me to solve the
> problem.
>
> Thank you for your help!!
>
> yours sincerely, cynthia
>
>
>
> <%
> varStudentID=Request.Form("StudentNo")
> Dim oRSd
> Set oRSd=Server.CreateObject("ADODB.Recordset")
> sqltext="SELECT * FROM StuGrp "
> sqltext=sqltext & " WHERE StudentID='" & varStudentID & "';"
> oRSd.Open sqltext, "DSN=openday"
>
> Response.Write "<TABLE BORDER=1>"
> Do While Not oRSd.EOF
> If varStudentID=oRSd("StudentNo") then
> Response.Write "<TR><TD>" & oRSd("StudentID") & "</TD>"
> Response.Write "<TD>" & oRSd("StudentName") & "</TD>"
> Response.Write "<TD>" & oRSd("GroupID") & "</TD></TR>"
> oRSd.MoveNext
> End if
> Loop
> Response.Write "no record"
> 'Response.Write "</TABLE>"
> %>
>
Message #3 by Ben Greenhouse <b.greenhouse@u...> on Wed, 28 Feb 2001 10:38:55 -0500
|
|
Hi Cynthia
I'm just a novice at all this stuff, and I do my DB open a little
differently - but I assume that method works for you. If I were writing
this code, I would use
Response.Write("<TABLE BORDER=1>")
If oRSd.RecordCount <> 0 then
Do While Not oRSd.EOF
If varStudentID=oRSd.Fields("StudentNo") then
Response.Write("<TR><TD>" & oRSd.Fields("StudentID") & "</TD>")
Response.Write("<TD>" & oRSd.Fields("StudentName") & "</TD>")
Response.Write("<TD>" & oRSd.Fields("GroupID") & "</TD></TR>")
oRSd.MoveNext
End if
Loop
else
Response.Write("no record")
end if
Response.Write("</TABLE>")
Instead of
Response.Write "<TABLE BORDER=1>"
Do While Not oRSd.EOF
If varStudentID=oRSd("StudentNo") then
Response.Write "<TR><TD>" & oRSd("StudentID") & "</TD>"
Response.Write "<TD>" & oRSd("StudentName") & "</TD>"
Response.Write "<TD>" & oRSd("GroupID") & "</TD></TR>"
oRSd.MoveNext
End if
Loop
Response.Write "no record"
'Response.Write "</TABLE>"
HTH...
Ben
Cynthia Halim wrote:
Hi,
I have been trying to find a record in the database from a user's input,
if the data is the same as the one in the database record, it will display
the record from the database. However, if the input is not the same as the
one in the record, it will keep looping until the EOF then display "no
record". I did the code below but it still doesnt work
Please tell me what is wrong with this code and help me to solve the
problem.
Thank you for your help!!
yours sincerely, cynthia
<%
varStudentID=Request.Form("StudentNo")
Dim oRSd
Set oRSd=Server.CreateObject("ADODB.Recordset")
sqltext="SELECT * FROM StuGrp "
sqltext=sqltext & " WHERE StudentID='" & varStudentID & "';"
oRSd.Open sqltext, "DSN=openday"
Response.Write "<TABLE BORDER=1>"
Do While Not oRSd.EOF
If varStudentID=oRSd("StudentNo") then
Response.Write "<TR><TD>" & oRSd("StudentID") & "</TD>"
Response.Write "<TD>" & oRSd("StudentName") & "</TD>"
Response.Write "<TD>" & oRSd("GroupID") & "</TD></TR>"
oRSd.MoveNext
End if
Loop
Response.Write "no record"
'Response.Write "</TABLE>"
%>
Message #4 by "Wally Burfine" <oopconsultant@h...> on Wed, 28 Feb 2001 15:26:55 -0000
|
|
Do you have 2 fields in the table with the same information? you are
selecting on StudentID then comparing to the field: StudentNo.
Regards,
Wally
>From: "Cynthia Halim" <cynthiahalim@h...>
>Reply-To: "ASP Databases" <asp_databases@p...>
>To: "ASP Databases" <asp_databases@p...>
>Subject: [asp_databases] Finding record in database w/ ASP
>Date: Wed, 28 Feb 2001 12:24:11
>
>Hi,
>
>I have been trying to find a record in the database from a user's input,
>if the data is the same as the one in the database record, it will display
>the record from the database. However, if the input is not the same as the
>one in the record, it will keep looping until the EOF then display "no
>record". I did the code below but it still doesnt work
>Please tell me what is wrong with this code and help me to solve the
>problem.
>
>Thank you for your help!!
>
>yours sincerely, cynthia
>
>
>
><%
> varStudentID=Request.Form("StudentNo")
> Dim oRSd
> Set oRSd=Server.CreateObject("ADODB.Recordset")
> sqltext="SELECT * FROM StuGrp "
> sqltext=sqltext & " WHERE StudentID='" & varStudentID & "';"
> oRSd.Open sqltext, "DSN=openday"
>
> Response.Write "<TABLE BORDER=1>"
> Do While Not oRSd.EOF
> If varStudentID=oRSd("StudentNo") then
> Response.Write "<TR><TD>" & oRSd("StudentID") & "</TD>"
> Response.Write "<TD>" & oRSd("StudentName") & "</TD>"
> Response.Write "<TD>" & oRSd("GroupID") & "</TD></TR>"
> oRSd.MoveNext
> End if
> Loop
> Response.Write "no record"
> 'Response.Write "</TABLE>"
>%>
Message #5 by "Quan Doan" <udoan25@h...> on Wed, 28 Feb 2001 08:45:46 -0800
|
|
Hi,
i guess you don't have to select all the fields from the table, why not just
select only the StudentID from the table? it is better for the search
process.
>From: "Wally Burfine" <oopconsultant@h...>
>Reply-To: "ASP Databases" <asp_databases@p...>
>To: "ASP Databases" <asp_databases@p...>
>Subject: [asp_databases] Re: Finding record in database w/ ASP
>Date: Wed, 28 Feb 2001 15:26:55 -0000
>
>Do you have 2 fields in the table with the same information? you are
>selecting on StudentID then comparing to the field: StudentNo.
>
>Regards,
>Wally
>
>
>>From: "Cynthia Halim" <cynthiahalim@h...>
>>Reply-To: "ASP Databases" <asp_databases@p...>
>>To: "ASP Databases" <asp_databases@p...>
>>Subject: [asp_databases] Finding record in database w/ ASP
>>Date: Wed, 28 Feb 2001 12:24:11
>>
>>Hi,
>>
>>I have been trying to find a record in the database from a user's input,
>>if the data is the same as the one in the database record, it will display
>>the record from the database. However, if the input is not the same as the
>>one in the record, it will keep looping until the EOF then display "no
>>record". I did the code below but it still doesnt work
>>Please tell me what is wrong with this code and help me to solve the
>>problem.
>>
>>Thank you for your help!!
>>
>>yours sincerely, cynthia
>>
>>
>>
>><%
>> varStudentID=Request.Form("StudentNo")
>> Dim oRSd
>> Set oRSd=Server.CreateObject("ADODB.Recordset")
>> sqltext="SELECT * FROM StuGrp "
>> sqltext=sqltext & " WHERE StudentID='" & varStudentID & "';"
>> oRSd.Open sqltext, "DSN=openday"
>>
>> Response.Write "<TABLE BORDER=1>"
>> Do While Not oRSd.EOF
>> If varStudentID=oRSd("StudentNo") then
>> Response.Write "<TR><TD>" & oRSd("StudentID") & "</TD>"
>> Response.Write "<TD>" & oRSd("StudentName") & "</TD>"
>> Response.Write "<TD>" & oRSd("GroupID") & "</TD></TR>"
>> oRSd.MoveNext
>> End if
>> Loop
>> Response.Write "no record"
>> 'Response.Write "</TABLE>"
>>%>
>
>
|
|
 |