Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

database

Options
  • 17-04-2002 10:38am
    #1
    Registered Users Posts: 47


    does anyone have the code to search an access database from a webpage, using either JavaScript or VBScript?


Comments

  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    You can't do that with Javascript or VBScript as they are both executed on the client side.
    To query a database you'll need to do it on the server side using something like PHP, JSP or ASP.


  • Registered Users Posts: 4,676 ✭✭✭Gavin


    two or three minutes of googling led to this
    http://developer.netscape.com/viewsource/kuslich_javascript.html

    Gav


  • Registered Users Posts: 761 ✭✭✭Terminator


    some simple asp/ado connection stuff :

    Set con = Server.CreateObject("ADODB.Connection")

    Con.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\yourdbase.mdb")

    SQL = "Select id, name from table"

    Set constring = Server.CreateObject("ADODB.Recordset")

    constring.ActiveConnection = Con
    constring.Open SQL

    do while not constring.eof

    response.write "name: "& constring("name") &"<BR>"
    response.write "id: "& constring("id") &"<BR>"

    constring.movenext
    loop

    constring.close
    set constring = nothing


  • Registered Users Posts: 706 ✭✭✭DJB


    Your wrong there, ENYGMA. You use VBScript or Javascript combined with SQL to do your server side scripting for your asp or jsp page, to access the database, filter the data and return the information in html format to the browser. How do you think PHP, JSP and ASP are coded? They are coded with VBScript or JavaScript!!!
    Originally posted by Enygma
    You can't do that with Javascript or VBScript as they are both executed on the client side.
    To query a database you'll need to do it on the server side using something like PHP, JSP or ASP.

    Here is a brief lesson on database connections, searching and displaying results.

    File 1 - connection.asp

    'This is a DSN-Less connection to open the set the path to the database.

    <%
    DBtype = "access"
    databasepath="dbase.mdb"
    databasepassword = "temp"
    datasourcename="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&server.mappath(databasepath)&";Jet OLEDB:Database Password=" & databasepassword
    cursortype = 3
    %>


    File 2 - search.asp

    'Graphically design the page and include a form on it like below.

    <form name="form1" method="post" action="results.asp">
    <input type="text" name="textfield" size="50">
    <input type="submit" name="textsearch" value="Search">
    </form>


    File 3 - results.asp

    'At the very top of your page before your html start tag put in the following:

    <%@LANGUAGE=&quot;VBSCRIPT"%> 'must be the first line on the page
    <!--#include file="connection.asp" -->

    <%
    'The following gets the information from the form on the previous page
    DIM search_criteria
    search_criteria = " "
    IF Request.Form("textsearch") <> "" THEN search_criteria = Request.Form("textsearch")
    %>

    <%
    'Now you must open the database and filter the data for the search criteria. tbl_information is the name of the table in the database and page_info is the name of the field within the table.
    SET rsResults = Server.CreateObject("ADODB.Recordset")
    rsResults.ActiveConnection = MM_connection_STRING
    rsResults.Source = "SELECT * FROM tbl_information WHERE page_info LIKE '%" & search_criteria & "%' ORDER BY id ASC"
    rsResults.CursorType = 0
    rsResults.CursorLocation = 2
    rsResults.LockType = 3
    rsResults.Open()
    rsResults_numRows = 0
    %>

    Then on your page your page somewhere you have to display the information. Use something like this on the page to write the information from the database to the web page.

    <% =rsResults.Fields.Item("page_info").Value %>

    That will display the first record on the page. To display a lot of different results on the one page, you must cycle through the records and display each individually... but that a lesson for another day.

    Try this and see how things go. When using ASP to connect to an Access database, you must be hosting your website on a Microsoft Based Server. If your running on Linux, you can use mySQL and PHP but the scripting is different to the above.


    All the best,

    Dave


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    How do you think PHP, JSP and ASP are coded? They are coded with VBScript or JavaScript!!!

    Huh?

    adam


  • Advertisement
  • Registered Users Posts: 2,660 ✭✭✭Baz_


    i think hes talking about the fact that you embed javascript or vbscript within your server side asp sections of the page, but to be honest DJB I would have answered the same way as I didnt know he meant through asp, and in fact he never mentioned asp. And also when I think of asp I think of asp, I forget the fact that its actually vbscript or javascript code your using, pretty stupid of me I know, but I just automatically make that distinction.

    But enygma in essence is right to say that with vbscript or javascript alone (no asp or other server side helping hands) its not possible to access a database.


  • Registered Users Posts: 706 ✭✭✭DJB


    You write you asp page in vbscript. It will only work as an asp page if you name it .asp. I know where you're coming from too. You also must take into account ADO.

    I was just correcting ENYGMA in that you use VBScript and JavaScript to program your asp and jsp pages, respectively, on the server side.

    Regards


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    I reckon Rasmus Lerdorf, Andi Gutmans and Zeev Suraski - not to mention the dozens of other PHP developers - would be offended at the mention of PHP... :)

    adam


  • Registered Users Posts: 706 ✭✭✭DJB


    I'm not a PHP developer so sorry for including PHP. I am a VBScript developer for ASP and thats what I know.

    Regards


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    How do you think PHP, JSP and ASP are coded? They are coded with VBScript or JavaScript!!!

    PHP is written in PHP.
    ASP can now be written in several languages.
    JSP is written in Java, not Javascript.
    Despite what you might think Java and Javascript are not at all related.

    Java is a fully object-oriented programming language, basically you can create you own classes and take advantage of object-oriented features such as polymorphism and inheritance.

    Javascript is a object-based language, meaning there are object available to you but you can't go creating your own. Also Javascript is usually executed on the client side, and I did point out that he'd have to use something like ASP, JSP or PHP to do it on the server side.

    So I wasn't actually wrong :p


  • Advertisement
  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    Javascript is a object-based language, meaning there are object available to you but you can't go creating your own.

    Course you can. That said, you were right about everything else. There's an awful lot of confusion out there about ASP, JSP, Java, JavaScript, VBScript, ASP, etc. Much less about good old PHP, eh? :)

    adam


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    Cool, wasn't aware of that. Learn something new every day and all that I guess. Thanks!

    Looks almost as bad as Perl's OOP though. :)


  • Registered Users Posts: 706 ✭✭✭DJB


    Alright, maybe a misunderstanding of words. I'll stick to ASP and VBScript programming as it is what I know and I won't comment on the others.

    I just thought you were saying ASP was a different programming language to VBScript as opposed to ASP being programmed in VbScript. No worries!!

    Regards


Advertisement