View Full Version : help pls...
madg3rr
06-18-2003, 09:13 PM
Can sumbody pls take alook at my code here & tell me wads wrong? i wan the system to validate the cpar no against the database but den it will show me "no records" wen there is such cparno in my database. so how? wads wrong? or wad m i missing?
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "CPAR"
SQL="Select * FROM Form WHERE CPAR_No='"&request("cparno")&"'"
set rs=Conn.Execute(SQL)
if rs.EOF then
response.write "no records"
else
if rs("CPAR_No")<>Request("cparno") then
response.write "wrong cparno..."
else
cpar=rs.Fields.Item("CPAR_No")
dept=rs.Fields.Item("Department")
response.redirect "process_bctd.asp"
end if
end if
rs.close
%>
Whitesword
06-18-2003, 09:44 PM
Your connection string to the database is missng some very important information.
Try something like:
<%
Dim Conn, SQL, rs
Dim cpar, dept
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("CPAR.mdb")
SQL="Select * FROM Form WHERE CPAR_No='"&request("cparno")&"'"
set rs=Conn.Execute(SQL)
if rs.EOF then
response.write "no records"
else
if rs("CPAR_No")<>Request("cparno") then
response.write "wrong cparno..."
else
cpar=rs.Fields.Item("CPAR_No")
dept=rs.Fields.Item("Department")
set rs=Nothing
Conn.Close
set Conn=Nothing
response.redirect "process_bctd.asp"
end if
end if
set rs=Nothing
Conn.Close
set Conn=Nothing
%>
madg3rr
06-18-2003, 11:07 PM
Hi, I've changed to wad u haf tell me to try out. But I does not make a diff... It still gives me the "no records" wen There is a record in my database. wad else do u think is wrong wif my code?
jsawkang
06-19-2003, 12:08 AM
Hi....
datatype for "CPAR_No" is of type number of text?
if is of number then u should put
SQL="Select * FROM Form WHERE CPAR_No=" &request("cparno")& ""
else
same with urs.
madg3rr
06-19-2003, 12:20 AM
it is of text type... wad ya mean same as mine? between the codes der is no diff rite except the connection... anywae i still haf the thing shown as "no records" wen der is suppose to be records...
jsawkang
06-19-2003, 12:25 AM
Hi...
i saw 1 typo in ur SQL statement.
should be "Select * FROM"
not "Select * FORM"
madg3rr
06-19-2003, 12:28 AM
dis correct... coz form is my table name... & i m not missing any from. dis is my sql statement....
SQL="Select * FROM Form WHERE CPAR_No='"&request("cparno")&"'"
jsawkang
06-19-2003, 12:34 AM
sorry, my oversight...
anyway, why don't u check whether ur "request("cparno")" got data or not?
just use response.write request("cparno") to check it.
then, the data is requested from form or querystring?
madg3rr
06-19-2003, 12:41 AM
cparno is retrieve from a form. i haf checked whether the cparno got data n yes it has a data.... so how cum wen i wanna validate against the database der is a problem....
i m suppose to display out all the fields using the cparno as my primary key. but i cant do it n it keeps showing me, "no records" error...
jsawkang
06-19-2003, 12:49 AM
ur code seem done have error.
anyway, try this out.
<%
Dim Conn, SQL, rs
Dim cpar, dept
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("CPAR.mdb")
sID=request.form("cparno")
SQL="Select * FROM Form WHERE CPAR_No='" & sID & "'"
set rs=Conn.Execute(SQL)
if rs.BOF or rs.EOF then
response.write "no records"
else
cpar=rs.Fields.Item("CPAR_No")
dept=rs.Fields.Item("Department")
set rs=Nothing
Conn.Close
set Conn=Nothing
response.redirect "process_bctd.asp"
end if
set rs=Nothing
Conn.Close
set Conn=Nothing
%>
madg3rr
06-19-2003, 12:56 AM
it still shows me the "no records"... yes i copied everything... & i've checked... i still dun get it...
jsawkang
06-19-2003, 01:00 AM
that strange.
in that case i don't think it's a coding error. sometime is the naming error. maybe u can try to the to name of the table called form to other name.
madg3rr
06-19-2003, 01:06 AM
well guez wad, it still does not show me record i wan. & it shows me yet agn "no records" i've changed my table name as have mentioned. do u think der is sumthing wrong wif the if statement instead???
<%
Dim Conn, SQL, rs
Dim cpar, dept
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("CPAS.mdb")
sID=request.form("cparno")
SQL="Select * FROM Info WHERE CPAR_No='" & sID & "'"
set rs=Conn.Execute(SQL)
if rs.BOF or rs.EOF then
response.write "no records"
else
cpar=rs.Fields.Item("CPAR_No")
dept=rs.Fields.Item("Department")
set rs=Nothing
Conn.Close
set Conn=Nothing
response.redirect "process_bctd.asp"
end if
set rs=Nothing
Conn.Close
set Conn=Nothing
%>
jsawkang
06-19-2003, 01:13 AM
why not try this way,
IF NOT rs.EOF Then
cpar=rs.Fields("CPAR_No")
dept=rs.Fields("Department")
response.write "cpar :" & cpar
reponse.write "dept :" & dept
else
response.write "No Record Found"
end if
why u need to redirect to another page? it's u want to page cpar and dept to that page? if u want to pass those 2 to another page then u better put those into Session.
example
Session("CPAR")=cpar
madg3rr
06-19-2003, 01:29 AM
ya i wanna pass the data to the process_bctd.asp... anywae i changed to wad u have mentioned but yet agn it shows me the "no records found"...
jsawkang
06-19-2003, 01:31 AM
i see...
jsawkang
06-19-2003, 01:33 AM
i see...
are u sure that u compare it with the correct fields? should can display the record if got record in that table.
madg3rr
06-19-2003, 02:05 AM
i haf checked agn & agn... all the variables i used is exactly the same. but y izit tad it still shows me no records found. i used all the cparno in my database but still cannot... haiz.. is der any other way tad i could actually validate the cparno against the database...
Angelika
06-19-2003, 09:24 AM
try
sID=Trim(request.form("cparno"))
madg3rr
06-19-2003, 07:49 PM
thanx angelika but then my program still doesnt work & I haf absoultely no idea wads wrong... dis is my code. i tried every method on my brain to see wads wrong but i still cant get it. izit possible if u all take alook at it or maybe help me find another alternative as to how to show the particular record using the id. sorry for the trouble...
<%
Dim Conn, SQL, rs
Dim cpar, dept
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("CPAS.mdb")
sID=Trim(request.form("cparno"))
SQL="Select * FROM Form WHERE CPAR_No='" & sID & "'"
set rs=Conn.Execute(SQL)
IF not rs.EOF Then
cpar=rs.Fields("CPAR_No")
dept=rs.Fields("Department")
response.write "cpar :" & cpar
response.write "dept :" & dept
else
response.write "No Record Found"
end if
set rs=Nothing
Conn.Close
set Conn=Nothing
%>
Try this
SQL="Select * FROM Form WHERE CPAR_No= " & sID
If that doesn't work comment out some of your code and check to see if sID is what it's suppose to be:
sID=Trim(request.form("cparno"))
SQL="Select * FROM Form WHERE CPAR_No='" & sID & "'"
'set rs=Conn.Execute(SQL)
'IF not rs.EOF Then
'cpar=rs.Fields("CPAR_No")
'dept=rs.Fields("Department")
'response.write "cpar :" & cpar
'response.write "dept :" & dept
'else
'response.write "No Record Found"
'end if
'set rs=Nothing
response.write sID
madg3rr
06-19-2003, 10:51 PM
Thanx realli lots but I've able to make it work by changing the codes... i used LIKE instead of = as my datatype is a text. den assign all the variables instead of using straight in the beginning... thanx fer thinkin of solutions fer guys. I appreciate it.
<%
cparno = trim(request.form("cparno"))
if cparno <> "" then
accessdb="CPAS"
table_name="form"
cn="driver={microsoft access driver (*.mdb)};"
cn=cn & "dbq=" & server.mappath(accessdb)
set rs = server.createobject("ADODB.Recordset")
sql = "select * from "& table_name &" where CPAR_No like '%%" & cparno & "%%' "
rs.Open sql, cn
if rs.eof or rs.bof then
response.write "No results found..."
observations=0
else
observations=1
end if
end if
%>
Angelika
06-20-2003, 09:41 AM
Did you try this?
cparno=Trim(request.form("cparno"))
strSQL="Select * FROM Form WHERE CPAR_No='"&cparno&"'"
rs.open strSQL,Conn
IF not rs.EOF Then
cpar=rs("CPAR_No")
dept=rs("Department")
response.write "cpar :" & cpar
response.write "dept :" & dept
else
response.write "No Record Found"
end if
madg3rr
06-20-2003, 09:45 AM
yesh i did try tad b4.... but dunno why it still cant be shown... after i changed my code completely den it cant be worked... i also dunno wer i go wrong... der seems to hab no errors but den it always show me no records found...
Angelika
06-20-2003, 10:48 AM
cparno=Trim(request.form("cparno"))
SQL = "select * from " & table_name
rs.open SQL,Conn
do until rs.eof
cpar=trim(rs("CPAR_No"))
IF cparno=trim(rs("CPAR_No")) Then
dept=rs("Department")
observations=1
End IF
rs.MoveNext
loop
rs.close
If observations=1 Then
response.write "cpar :" & cpar
response.write "dept :" & dept
Else
response.write "No Record Found"
End IF
hmm
i tried to remove my post , is this possible?
vBulletin v3.0.3, Copyright ©2000-2012, Jelsoft Enterprises Ltd.