Link to home
Start Free TrialLog in
Avatar of hiepbeo
hiepbeo

asked on

Expected statement ????????????????

I have a question . I think syntax is good !

I don't know why i get this error ????
Error Type:
Microsoft VBScript compilation (0x800A0400)
Expected statement
/web/code/xulythemsach.asp, line 15
End if

Here is code:
<%
strconn = "Provider = Microsoft.Jet.OleDB.4.0; Data Source =" & Server.MapPath("../assets/data.mdb") & ";"
set conn = Server.CreateObject("ADODB.Connection")        ' connect
set rs = Server.CreateObject("ADODB.RecordSet")         'RecordSet
'Mo ket noi voi CSDL
conn.Open Strconn
Dim Book
Dim  checkbook
book = request.Form("taifile")
Id = request("id")
checkbook = "select path from tblBooks "
Chk = Conn.Execute(checkbook)
Do until chk.EOF
      if Checkbook = Book then response.redirect"themsach.asp?error=Exists!"
      End if (line 15)
chk.movenext
loop
 strSQL = "INSERT INTO tblBooks(name,lang,path,format,author,publishing,imgpath,keywords) values('" & request.Form("Tensach") & "', '" & request.Form("ngonngu") & "','" & request.Form("taifile") & "','" & request.Form("loaifile") & "','" & request.Form("txttg") & "','" & request.Form("txtnxb") & "','" & request.Form("anh") & "','" & request.Form("Tukhoa") & "')"
Set RS = Conn.Execute(strSQL)
set RS = nothing
%>

Avatar of HuyBD
HuyBD
Flag of Viet Nam image

Just for ASP proccessing, you must breaking in line 14

Do until chk.EOF
     if Checkbook = Book then
          response.redirect"themsach.asp?error=Exists!"
     End if
chk.movenext
loop
Avatar of hiepbeo
hiepbeo

ASKER

Another error here. (I followed your support)
Error Type:
Microsoft VBScript runtime (0x800A01B6)
Object doesn't support this property or method: 'Chk.EOF'
/web/code/xulythemsach.asp, line 14
Avatar of Ryan Chong
something like this.. ?


<%
strconn = "Provider = Microsoft.Jet.OleDB.4.0; Data Source =" & Server.MapPath("../assets/data.mdb") & ";"
set conn = Server.CreateObject("ADODB.Connection")       ' connect
set rs = Server.CreateObject("ADODB.RecordSet")        'RecordSet
'Mo ket noi voi CSDL
conn.Open Strconn
Dim Book
Dim  checkbook
book = request.Form("taifile")
Id = request("id")
checkbook = "select path from tblBooks "
rs.open checkbook, Conn, 1, 1

Do while rs.EOF = false
     if Checkbook = Book then
             response.redirect"themsach.asp?error=Exists!"
     End if
   rs.movenext
loop

 strSQL = "INSERT INTO tblBooks(name,lang,path,format,author,publishing,imgpath,keywords) values('" & request.Form("Tensach") & "', '" & request.Form("ngonngu") & "','" & request.Form("taifile") & "','" & request.Form("loaifile") & "','" & request.Form("txttg") & "','" & request.Form("txtnxb") & "','" & request.Form("anh") & "','" & request.Form("Tukhoa") & "')"
Set RS = Conn.Execute(strSQL)
set RS = nothing
%>
strSQL = "INSERT INTO tblBooks(name,lang,path,format,author,publishing,imgpath,keywords) values('" & request.Form("Tensach") & "', '" & request.Form("ngonngu") & "','" & request.Form("taifile") & "','" & request.Form("loaifile") & "','" & request.Form("txttg") & "','" & request.Form("txtnxb") & "','" & request.Form("anh") & "','" & request.Form("Tukhoa") & "')"
Set RS = Conn.Execute(strSQL)
set RS = nothing

should be as:

strSQL = "INSERT INTO tblBooks(name,lang,path,format,author,publishing,imgpath,keywords) values('" & request.Form("Tensach") & "', '" & request.Form("ngonngu") & "','" & request.Form("taifile") & "','" & request.Form("loaifile") & "','" & request.Form("txttg") & "','" & request.Form("txtnxb") & "','" & request.Form("anh") & "','" & request.Form("Tukhoa") & "')"
Conn.Execute(strSQL)
Rs.Close
set RS = nothing
'Conn.close
'set conn = nothing
...
becausre Chk is recordset object so you need add set statement
Set Chk = Conn.Execute(checkbook)
You specified rs as a recordset so why are u usign Chk as a recordset?

get rid of this line

Chk = Conn.Execute(checkbook)

and replace it with

rs.open checkbook, conn

then isntead of

chk.EOF do rs.EOF


Leo
Avatar of hiepbeo

ASKER

Hi everybody ! Thanks for your immediate response. Now it worked, but it doesn't work as i think. I want to compare between 2 value, the first is the value book we can request from text box "taifile". The second is taken from the columns path form database. If 2 value is equal, display "Error!". If not, we will insert info into database. This code is work with no error. But when i try to insert the two value which is the same, all are inserted into database.
here: http://www.eric.trada.us/trung.jpg

WHY ?? Hope that everybody will solve this problem for me. Thanks!
 Here are the code (server php,so you can access it as text file):
http://www.eric.trada.us/themsach.asp 
http://www.eric.trada.us/xulythemsach.asp

 In brief:
file processsearch.asp

<%
strconn = "Provider = Microsoft.Jet.OleDB.4.0; Data Source =" & Server.MapPath("../assets/data.mdb") & ";"
set conn = Server.CreateObject("ADODB.Connection")       ' connect
set rs = Server.CreateObject("ADODB.RecordSet")        'RecordSet
'Mo ket noi voi CSDL
conn.Open Strconn
Dim Book
Dim  checkbook
book = request.Form("taifile")
Id = request("id")
checkbook = "select path from tblBooks "
rs.open checkbook, Conn, 1, 1
Set Chk = Conn.Execute(checkbook)

Do while rs.EOF = false
     if Checkbook = Book then
             response.redirect"themsach.asp?error=Sách &#273;ã có trong th&#432; vi&#7879;n. Xin vui lòng nh&#7853;p sách khác!"
     End if
   rs.movenext
loop
 strSQL = "INSERT INTO tblBooks(name,lang,path,format,author,publishing,imgpath,keywords) values('" & request.Form("Tensach") & "', '" & request.Form("ngonngu") & "','" & request.Form("taifile") & "','" & request.Form("loaifile") & "','" & request.Form("txttg") & "','" & request.Form("txtnxb") & "','" & request.Form("anh") & "','" & request.Form("Tukhoa") & "')"
Conn.Execute(strSQL)
Rs.Close
set RS = nothing
'Conn.close
'set conn = nothing
%>
>>if Checkbook = Book then

if Checkbox equals to "select path from tblBooks ", this will never matched...
obviously this check, Checkbook = Book is not working correctly

print out the values of Checkbook and book before the line

Checkbook = Book and see what they are.

you can also try

if Trim(checkBook) = Trim(book) then
etc.


Leo
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hiepbeo

ASKER

Wonderful ! This code is working with full of its function .Thanks everybody ! Especially ryancys
You're welcome, glad could make helps here, cheers