You must Sign In to post a response.

how to connect javascript to an SQL database

Hi all,
how to connect javascript to an SQL database


#261569    Author: Deepa    10 Jul 2008 Member Level: Gold   Points : 6

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 %>
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" -->

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

Set oRecordset = nothing
Set oConnection = nothing


#261587    Author: Nithya    10 Jul 2008 Member Level: Gold   Points : 6


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

<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 + "'";

rs.Open(SQL, cn);
surname.value = rs(0);
DOB.value = rs(1);



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


#261624    Author: sathiya  10 Jul 2008 Member Level: Silver   Points : 6

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"))
sql="SELECT * FROM customers"
dbcomm=New OleDbCommand(sql,dbconn)
end sub
<body> <form runat="server">
<asp:Repeater id="customers" runat="server">
<table border="1" width="100%">

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.