Tuesday, May 1, 2012

Database Connectivity using ASP

                                         Database Connectivity using  ASP 

Using ASP we can establish a database connection using the following code:

Dim objConn
set objConn=Server.CreateObject("ADODB.Connection")
objConn.Connectionstring="PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Inetpub\wwwroot\ip\feedback.mdb"
objConn.Open 

NOTE:here the database is created in MS Access 2000-2003 format.

For adding records to the database,try the following code:

<html>
<body>
<%
Dim f,l,c,e,co,sql
'Getting information from the submitted form
f= Request.Form("fn")
l=Request.Form("ln")
c=Request.Form("cno")
e= Request.Form("email")
co=Request.Form("com")
Dim objConn
set objConn=Server.CreateObject("ADODB.Connection")
objConn.Connectionstring="PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Inetpub\wwwroot\ip\feedback.mdb"
objConn.Open
sql = "INSERT INTO [sugest] ([fname],[lname],"
sql = sql & "[contactno],[email-id],[comment])"
sql = sql & " VALUES "
sql = sql & "('" & f & "',"
sql = sql & "'" & l & "',"
sql = sql & "'" & c & "',"
sql = sql & "'" & e & "',"
sql = sql & "'" & co & "')"
objConn.Execute sql
objConn.close
response.write("THANK YOU !")
%>

</body>
</html>  

Hope..this may help you!!

No comments:

Post a Comment