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




Responses

#261569    Author: Deepa      Member Level: Gold      Member Rank: 176     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 %>
<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    Author: Nithya      Member Level: Gold      Member Rank: 777     Date: 10/Jul/2008   Rating: 2 out of 52 out of 5     Points: 6

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





 
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
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India