Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Dec 2011
    Posts
    29
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Internet Explorer Error Type:Microsoft VBScript compilation (0x800A0401)Expected end of statement

    when i am retriving the records from sqlserver2005 by using ASP.The folloying error is coming

    Error Type:
    Microsoft VBScript compilation (0x800A0401)
    Expected end of statement
    /MyWeb/student_db_new.asp, line 21, column 10
    foreach x In rs.Fields
    ---------^


    my code is

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head><title> ADO-List DatabaseRecords</title></head>
    <body>
    <%
    Dim conn,rs,x
    Set conn=Server.CreateObject("ADODB.Connection")
    conn.provider="Microsoft.Jet.OLEDB.4.O"
    conn.open(Server.mappath("db/Student"))

    Set rs=Server.CreateObject("ADODB.RecordSet")
    rs.open "select*from tblClass",conn
    %>

    <h2>List Database Table</h2>
    <p> Click on a button to modify a record </p>
    <table border="1" width="100%">
    <tr bgcolor="#b0c4de">

    <%
    For Each x In rs.Fields
    response.write("<th>" &UCase(x.name) &"</th>")
    rs.MoveNext

    %>
    </tr>

    <% Do Until rs.EOF %>

    <tr bgcolor="f0f0f0">
    <form method="post" action="Student_db_edit.asp" target="_blank">

    <%
    For Each x In rs.Fields
    If x.name="studentID" Then %>

    <td> <input type="submit" name="studentID" value="<%x.value%>"></td>

    <% Else %>
    <td> <%respone.Write(x.value)%></td>
    <% End If Next %>
    </ form >
    <rs.MoveNext%>
    </tr>
    loop
    rs.close
    set rs=nothing
    conn.close
    set conn=nothing
    %>
    </table>


    </body>
    </html>

    please tell me where do i mistake

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,677
    Thanks
    80
    Thanked 4,645 Times in 4,607 Posts
    You must put a SPACE between FOR and EACH.
    Code:
    For Each x In rs.Fields
    In the code you show, you have a space there. But the error message clearly is saying there is no space, so check your code again.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Dec 2011
    Posts
    29
    Thanks
    6
    Thanked 0 Times in 0 Posts
    could you show my code i already provide the space between for each

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,677
    Thanks
    80
    Thanked 4,645 Times in 4,607 Posts
    Yes, I *DO* see the space in your code.

    But the ERROR MESSAGE you showed does *NOT* have the space there.

    Maybe you are trying to run an OLD version of your code?

    When I used
    Code:
    foreach x In rs.Fields
    (no space) in a test, I *did* get the same message you got.

    Make sure you are running the latest version of your code.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    prashanth193 (12-10-2011)

  • #5
    New Coder
    Join Date
    Dec 2011
    Posts
    29
    Thanks
    6
    Thanked 0 Times in 0 Posts
    thanks,I have rectified that error and i have got one more runtime error that is
    Error Type:
    Microsoft VBScript runtime (0x800A01A8)
    Object required: ''
    /MyWeb/student_db_new.asp, line 40




    code is
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head><title> ADO-List DatabaseRecords</title></head>
    <body>
    <%
    Dim conn,rs,x
    Set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="SQLOLEDB.1;Persist Security Info=False;User ID=sa;password=123;Initial Catalog=Student;Data Source=MONTESSO-DFA5BB"
    conn.open

    Set rs=Server.CreateObject("ADODB.RecordSet")
    rs.open "select*from tblClass",conn
    %>

    <h2>List Database Table</h2>
    <p> Click on a button to modify a record </p>
    <table border="1" width="100%">
    <tr bgcolor="#b0c4de">

    <%
    For Each x In rs.Fields
    response.write("<th>" &UCase(x.name) &"</th>")
    Next

    %>
    </tr>

    <% Do Until rs.EOF %>

    <tr bgcolor="f0f0f0">
    <form method="post" action="Student_db_edit.asp" target="_blank">

    <%
    For Each x In rs.Fields
    If x.name="studentID" Then %>

    <td> <input type="submit" name="studentID" value="<%=x.value%>"></td>

    <% Else %>
    <td> <%Respone.Write(x.value)%></td>
    <% End If
    Next
    loop
    %>
    </ form >
    <rs.MoveNext%>
    </tr>
    loop
    rs.close
    set rs=nothing
    conn.close
    set conn=nothing
    %>
    </table>


    </body>
    </html>

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,677
    Thanks
    80
    Thanked 4,645 Times in 4,607 Posts
    You spelled "Response" wrong. Look carefully at it:

    Code:
    Respone.Write(x.value)
    Missing the "s" before the last "e".
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,677
    Thanks
    80
    Thanked 4,645 Times in 4,607 Posts
    You know, you could have coded that as
    Code:
        <td><%=x.value%></td>
    Also, Response.Write really shouldn't use ( ) around it's arguments.
    Code:
       Response.Write x.value
    is better. The ( ) don't hurt, but they slow it down just a tiny bit.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    prashanth193 (12-10-2011)

  • #8
    New Coder
    Join Date
    Dec 2011
    Posts
    29
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Error Type:
    Microsoft VBScript compilation (0x800A0401)
    Expected end of statement
    /MyWeb/Student_db_edit.asp, line 12, column 49
    rs.Open "Select * from tblClass where tblClass.["studentID"]="&studentid,conn
    ------------------------------------------------^
    the above error is occur most of times where it occurs and how can we solve that


    code is

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <%
    studentid=Request.Form("studentID")
    If studentid="" then response.end
    Dim conn,rs,x
    Set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="SQLOLEDB.1;Persist Security Info=False;User ID=sa;password=123;Initial Catalog=Student;Data Source=MONTESSO-DFA5BB"
    conn.open

    Set rs=Server.CreateObject("ADODB.Recordset")
    set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open "Select * from tblClass where tblClass.["studentID"]="&studentid,conn %>
    <html>
    <head>
    <title>ADO - Edit DataBase Record</title>

    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    </head>
    <body>
    <h2>Edit Database Table</h2>
    <form method="post" action="demo_db_submit.asp" target="_blank">
    <input name="studentID" type="hidden" value=<%=studentid%>>
    <table bgcolor="#b0c4de">
    <%
    for each x in rs.Fields
    if x.name <> "studentID" then%>
    <tr>
    <td><%=x.name%> </td>
    <td><input name="<%=x.name%>" value="<%=x.value%>" size="20"></td>
    <%end if
    next

    rs.close
    conn.close
    %>
    </tr>
    </table>
    <br />
    <input type="submit" name="action" value="Save">
    <input type="submit" name="action" value="Delete">
    </form>

    <p><a href="showcode.asp?source=demo_db_edit">View source on how to create input fields based on the fields from one record in the database table</a>.</p>
    <p><b>Note:</b> If you click on "Save" or "Delete" a new page will open. On the new page you may look at the source on how to submit changes to, or delete from a database table.</p>
    </body>
    </html>
    Last edited by prashanth193; 12-10-2011 at 10:15 AM.

  • #9
    New Coder
    Join Date
    Dec 2011
    Posts
    29
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Error Type:
    Microsoft VBScript compilation (0x800A0401)
    Expected end of statement
    /MyWeb/Student_db_edit.asp, line 12, column 49
    rs.Open "Select * from tblClass where tblClass.["studentID"]="&studentid,conn
    ------------------------------------------------^
    the above error is occur most of times where it occurs and how can we solve that


    code is

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <%
    studentid=Request.Form("studentID")
    If studentid="" then response.end
    Dim conn,rs,x
    Set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="SQLOLEDB.1;Persist Security Info=False;User ID=sa;password=123;Initial Catalog=Student;Data Source=MONTESSO-DFA5BB"
    conn.open

    Set rs=Server.CreateObject("ADODB.Recordset")
    set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open "Select * from tblClass where tblClass.["studentID"]="&studentid,conn %>
    <html>
    <head>
    <title>ADO - Edit DataBase Record</title>

    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    </head>
    <body>
    <h2>Edit Database Table</h2>
    <form method="post" action="demo_db_submit.asp" target="_blank">
    <input name="studentID" type="hidden" value=<%=studentid%>>
    <table bgcolor="#b0c4de">
    <%
    for each x in rs.Fields
    if x.name <> "studentID" then%>
    <tr>
    <td><%=x.name%> </td>
    <td><input name="<%=x.name%>" value="<%=x.value%>" size="20"></td>
    <%end if
    next

    rs.close
    conn.close
    %>
    </tr>
    </table>
    <br />
    <input type="submit" name="action" value="Save">
    <input type="submit" name="action" value="Delete">
    </form>

    <p><a href="showcode.asp?source=demo_db_edit">View source on how to create input fields based on the fields from one record in the database table</a>.</p>
    <p><b>Note:</b> If you click on "Save" or "Delete" a new page will open. On the new page you may look at the source on how to submit changes to, or delete from a database table.</p>
    </body>
    </html>

  • #10
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,677
    Thanks
    80
    Thanked 4,645 Times in 4,607 Posts
    You should *NOT* have the " marks in there.

    Code:
    rs.Open "Select * from tblClass where tblClass.["studentID"]="&studentid,conn %>
    Should be simply:
    Code:
    rs.Open "Select * from tblClass where tblClass.studentID=" & studentid, conn 
    %>
    You *can* have the [...] but they are *NOT* needed. You only use them when a table or field name is a SQL keyword or when the name has a space or other special character in it.

    For example:
    Code:
    SELECT [select],[first-name] FROM table
    You need the [..] around select because it is a keyword in SQL.
    You need the [..] around first-name because otherwiser the - would be seen as a minus sign.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    prashanth193 (12-11-2011)

  • #11
    New Coder
    Join Date
    Dec 2011
    Posts
    29
    Thanks
    6
    Thanked 0 Times in 0 Posts
    sir in the above code the sql statement(rs.Open "Select * from tblClass where tblClass.studentID=" & studentid, conn )
    that is not retriving the particular record of the particular student id.
    Actually i want the particular record of the particular student when i am pressing the studentid button.Below mention the code is executed successfully it wont give any error but it is not retrive the particular record.It retrives only first record of the table.Please tell me where it's wrong by seen the following code.


    <%
    studentID=Request.Form("studentID")
    response.write studentID
    If studentID="" Then response.End
    Set conn=Server.CreateObject("ADODB.Connection")
    conn.provider="SQLOLEDB.1;Persist Security Info=False;User ID=sa;password=123;Initial Catalog=Student;Data Source=MONTESSO-DFA5BB"
    conn.open

    Set rs=Server.CreateObject("ADODB.Recordset")
    rs.open "select *from tblClass where tblClass.studentID="&"studentID",conn


    %>
    <html>
    <head>
    <title>ADO -Edit DataBase Record</title>
    </head>
    <body>
    <h2>Edit DataBase Table</h2>
    <form method="post" action="student_db_submit.asp" target="_blank">
    <input name="studentID" type="hidden" value=<%=studentID%>>
    <table bgcolor="#b0c4de">
    <%
    For Each x In rs.Fields
    response.write x.name
    response.write x.value
    If x.name <> "studentID" Then %>
    <tr>
    <td> <%=x.name%> </td>
    <td> <input name="<%=x.name%>" value="<%=x.value%>" size="20"></td>
    <%End If
    Next

    rs.close
    conn.close
    %>
    </tr>
    <table>
    <br/>

    <input type="submit" name="action" value="Save">
    <input type="submit" name="action" value="Delete">
    </form>
    </html>

  • #12
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,677
    Thanks
    80
    Thanked 4,645 Times in 4,607 Posts
    Well, the code looks right. So now you need to learn to DEBUG DEBUG DEBUG.

    I'd start with this:
    Code:
    <%
    studentID=Request.Form("studentID")
    response.write studentID
    If studentID="" Then response.End
    Set conn=Server.CreateObject("ADODB.Connection")
    conn.provider="SQLOLEDB.1;Persist Security Info=False;User ID=sa;password=123;Initial Catalog=Student;Data Source=MONTESSO-DFA5BB"
    conn.open
    
    SQL = "select *from tblClass where tblClass.studentID="&"studentID"
    Response.Write "DEBUG SQL: " & SQL & "<hr/>"
    
    Set rs = conn.Execute(SQL) ' more efficient way to create a recordset
    %>
    Then take the SQL that the above shows you and go use a Database utility program (that is, do *NOT* use ASP code) to run that same query and see what you get.

    If the SQL looks good, the problem may be in your database. You won't know that without debugging.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #13
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,677
    Thanks
    80
    Thanked 4,645 Times in 4,607 Posts
    By the way, this is a bad idea:
    Code:
    <input type="submit" name="action" value="Save">
    <input type="submit" name="action" value="Delete">
    If you ever start using JavaScript code with your <form>s, a field named action will *HIDE* the <form>'s action= from JavaScript.

    Easy solution: Just spell it with an upper case "A":
    Code:
    <input type="submit" name="Action" value="Save">
    <input type="submit" name="Action" value="Delete">
    JavaScript is case sensitive, so "action" and "Action" are different to it. You ASP code won't know the difference, because the Request object is *not* case sensitive.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    prashanth193 (12-17-2011)

  • #14
    New Coder
    Join Date
    Dec 2011
    Posts
    29
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Internet Explorer got the error when i am generating studentid dynamically

    i got the following error when i am generate the studentid dynamically
    Error Type:
    Microsoft VBScript compilation (0x800A03EA)
    Syntax error
    there is no error occur but i not eble to generate the studentID dynamically,By using the following code i am inserted the data in their respective fields but there is no value inserted into the studentID column that is not generated dynamiclly please tell where can i done mistake


    code is

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title>ADO - Add DataBase Record</title>
    </head>
    <body>
    <h2>Add Record to a Database Table</h2>

    <%
    on error resume next
    set conn=Server.CreateObject("ADODB.Connection")
    conn.provider="SQLOLEDB.1;Persist Security Info=False;User ID=sa;password=123;Initial Catalog=Student;Data Source=MONTESSO-DFA5BB"
    conn.open

    Set comm=Server.CreateObject("ADODB.Command")
    comm.ActiveConnection=conn
    comm.CommandText="select max(studentID) from tblClass"
    Set str=comm.Execute
    response.write(str)

    Set comm=Server.CreateObject("ADODB.Command")
    comm.ActiveConnection=conn
    comm.CommandText="select substring(str,3,6) from tblClass"
    Set str2=comm.Execute
    set str2=str2+1

    set sID="&MS&" +str2

    student Id=sID
    fname=Request.Form("fname")
    lname=Request.Form("lname")
    class1=Request.Form("class")
    section=Request.Form("section")
    emailID=Request.Form("emailID")


    sql="INSERT INTO tblClass (studentID,fname,lname,class,section,emailID) VALUES "
    sql=sql & "('" & studentID &"','" & fname & "','" & lname & "','" & class1 & "','" & section & "',"
    sql=sql & "'" & emailID & "')"

    conn.Execute sql,recordsaffected
    if err <> 0 then
    Response.Write("You do not have permission to update this database!")
    else
    Response.Write(Recordsaffected & " record added")
    end if

    conn.close
    %>
    <form method="post" action="Student_db_new.asp" target="_blank">
    <input type="submit" value="DetailOfTheClassStudents">
    </form>
    </body>
    </html>
    Last edited by prashanth193; 12-17-2011 at 02:25 PM.

  • #15
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,677
    Thanks
    80
    Thanked 4,645 Times in 4,607 Posts
    First of all, I just notice that your earlier post was wrong and I missed it before.
    Code:
    rs.open "select *from tblClass where tblClass.studentID="&"studentID",conn
    WRONG! The quotes around "studentID" at the end there are bogis.

    Should be
    Code:
    rs.open "select *from tblClass where tblClass.studentID=" & studentID,conn
    As to this newest bug: You don't say what line number the message refers to.

    You need to know that "compilation error" means that your code isn't even legal code. That is, your code won't even *TRY* to run because VBScript can't make any sense out of it.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •