Forums » .NET » JavaScript »

how to connect javascript to an SQL database

Posted Date: 09 Jul 2008      Posted By:: Revathi Prasannaa     Member Level: Silver  Member Rank: 0     Points: 1   Responses: 3

Hi all,
how to connect javascript to an SQL database


#261569    Author: Deepa      Member Level: Gold      Member Rank: 0     Date: 10/Jul/2008   Rating: 2 out of 52 out of 5     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      Member Level: Gold      Member Rank: 0     Date: 10/Jul/2008   Rating: 2 out of 52 out of 5     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      Member Level: Silver      Member Rank: 0     Date: 10/Jul/2008   Rating: 2 out of 52 out of 5     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%">

Post Reply     

 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.

  • Return to Discussion Forum
  • Start new thread

  • Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India