You must Sign In to post a response.
  • Category: JavaScript

    how to connect javascript to an SQL database

    Hi all,
    how to connect javascript to an SQL database
  • #261569
    Here is the simplest example to get you started. You just need to change the ODBC connection and table information to match yours.
    ------------------------------------

    <%@ LANGUAGE = VBScript %>
    <% Option Explicit %>
    <html>
    <head>
    <style>
    body, html {margin:0px; padding: 0px; overflow: hidden;font: menu;border: none;} </style>
    <link href="../../runtime/styles/xp/grid.css" rel="stylesheet" type="text/css" ></link>
    <script src="../../runtime/lib/grid.js"></script>
    <!-- #INCLUDE FILE="activewidgets.asp" -->
    </head>
    <body>

    <%
    Dim oConnection, oRecordset
    Set oConnection = Server.CreateObject("ADODB.Connection")
    oConnection.Open "IntranetSQL"
    Set oRecordset = oConnection.Execute("SELECT * FROM Employees")

    Response.write(activewidgets_grid("obj", oRecordset))

    'Alternate method via recordset
    'do while not oRecordset.eof
    'str = str & oRecordset("FirstName") & "," & oRecordset("LastName") & vbCrlf
    'movenext
    'loop

    oRecordset.close
    Set oRecordset = nothing
    oConnection.close
    Set oConnection = nothing
    %>

    </body>
    </html>

    http://www.activewidgets.com/javascript.forum.262.11/how-to-connect-to-sql.html

    http://www.activewidgets.com/javascript.forum.263.1/how-to-connect-to-sql.html

  • #261587
    hi...

    here i have given the example program for accessing database...

    <html>
    <head>
    <title>Entitled Document</title>
    <script language="JavaScript" >

    function getSubmit()
    {
    var LastName;
    var Firstn = names.value ;

    var cn = new ActiveXObject("ADODB.Connection");
    //here you must use forward slash to point strait
    var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:/clientDB.mdb";
    var rs = new ActiveXObject("ADODB.Recordset");
    //var SQL = "INSERT INTO Customers(FirstName, Surname)"
    //+ " VALUES ( '"+ names.value +"', '" + surname.value +"')";
    var SQL = "select Surname, DOB from Customers where FirstName = '" + Firstn + "'";

    cn.Open(strConn);
    rs.Open(SQL, cn);
    surname.value = rs(0);
    DOB.value = rs(1);
    //alert(rs(0));
    rs.Close();
    cn.Close();


    }

    </script>
    </head>
    <body>

    <input type="text" name="names" />
    <input type="text" name="surname" />
    <input type="text" name="DOB" />
    <input type="button" value="submit" onclick="getSubmit()">

    </body>
    </html>

  • #261624
    HI in the following code i connected javascript with ms-access database.U modify it sql database

    <%@ Import Namespace="System.Data.OleDb" %>
    <script runat="server">
    sub Page_Load
    dim dbconn,sql,dbcomm,dbread
    dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
    data source=" & server.mappath("northwind.mdb"))
    dbconn.Open()
    sql="SELECT * FROM customers"
    dbcomm=New OleDbCommand(sql,dbconn)
    dbread=dbcomm.ExecuteReader()
    customers.DataSource=dbread
    customers.DataBind()
    dbread.Close()
    dbconn.Close()
    end sub
    </script>
    <html>
    <body> <form runat="server">
    <asp:Repeater id="customers" runat="server">
    <HeaderTemplate>
    <table border="1" width="100%">
    <tr>
    <th>Companyname</th>
    <th>Contactname</th>
    <th>Address</th>
    <th>City</th>
    </tr>
    </HeaderTemplate>
    <ItemTemplate>
    <tr>
    <td><%#Container.DataItem("companyname")%></td>
    <td><%#Container.DataItem("contactname")%></td>
    <td><%#Container.DataItem("address")%></td>
    <td><%#Container.DataItem("city")%></td>
    </tr>
    </ItemTemplate>
    <FooterTemplate>
    </table>
    </FooterTemplate>
    </asp:Repeater>
    </form>
    </body>
    </html>


This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.