ASP With Database

Tips >> ASP

WANTS TO MAKE SOFTWARE WITHOUT KNOWLEDGE OF ASP? CLICK HERE


These article will explain you how to use ASP with Database. Databases are stored on a computer system as files. A database program or a database management system manipulates the information as needed and reports on it accordingly. The driving force behind Active Server technologies is data access. In order to develop a truly dynamic web site developers need to allow users to access data on demand. Luckily, with Microsoft's Active Server Pages, this is exceedingly easy to do. This article for ASP beginners details how to connect to a SQL Server 7.0 database using ActiveX Data Object (ADO) and Open Database Connectivity (ODBC).

In order to illustrate the process of connecting to a data source with ASP, we will need to do three things :-

  • Create a database
  • Create an ODBC data source name (DSN)
  • Create an ASP page

In this article I will guide you through the steps of creating a simple but effective search engine. We will divide our work into two steps :-

  • Create a set of ASP pages to index the site content.
  • Create a search engine to offer keyword specific database dependant search to our visitors.


Creating 'addtodb.asp' page

Open note pad or your favorite text editor and create a new page. Save it as 'addtodb.asp'. Now copy paste the following code into it :-

It can be better explained by an example :-

Example#1 :-

Code :-
<!--#include file="editme.asp"-->
<html>
<head>
<style>
body { font-family : Times New Roman; font-size : 8pt; }
</style>
</head>
<body>

<%
On Error Resume Next
Dim geturl, title, description, keywords, strURL, strDB, con, results

' URL
strURL = Request.QueryString("look_for")

Set geturl = CreateObject("Stardeveloper.GetURL")
strFileContents = geturl.Get(strURL)
Set geturl = Nothing

' Keywords
key1 = InStr(1, strFileContents, "<meta name=""keywords"" content=""", 1)
key1 = key1 + Len("<meta name=""keywords"" content=""")
key2 = InStr(key1, strFileContents, """>", 1)

keywords = "," & Trim(Mid(strFileContents, key1, (key2 - key1))) & ","
keywords = Replace (keywords, "'", " ")

' Description
desc1 = InStr(1, strFileContents, "<meta name=""description"" content=""", 1)
desc1 = desc1 + Len("<meta name=""description"" content=""")
desc2 = InStr(desc1, strFileContents, """>", 1)

description = Trim(Mid(strFileContents, desc1, (desc2 - desc1)))
description = Replace (description, "'", " ")

' Title
tit1 = InStr(1, lcase(strFileContents), "<title>", 1)
tit1 = tit1 + Len("<title>")
tit2 = InStr(tit1, strFileContents, "</title>", 1)

title = Trim(Mid(strFileContents, tit1, (tit2 - tit1)))
title = Replace (title, "'", " ")

' Our Connection Object
Set con = CreateObject("ADODB.Connection")
con.Open strDB
Set results = con.Execute("select title, description, keywords _
from all_pages where url = '" & strURL & "'")

' If the returning recordset is empty the add the URL with accompanying
' info to the database
If results.EOF Then
con.Execute("insert into all_pages (title, description, keywords, url, _
mydate) values ('" & title & "', '" & description & "', '" & _
keywords & "', '" & strURL & "', '" & date & "')")
Set rs = con.Execute("select count(url) as total_count from all_pages")
cnt = rs("total_count")
Set rs = Nothing
Response.Write "<b>New account successfully created for " & strURL & " _
.</b>" & vbcrlf
Response.Write "<br>"
Response.Write "Total Pages Indexed : " & cnt & vbcrlf
Else
' But if the returning recordset is not empty i.e. we have already added _
' title, desc, keywords etc into it then update that information with the _
' new one.
con.Execute("update all_pages set title = '" & title & "', description = _
'" & description & "', keywords = '" & keywords & "', mydate = #" _
& date & "# where url = '" & strURL & "'")
Response.Write "<b>Account updated successfully.</b>"
End If

' Done. Now release Objects
Set results = Nothing
con.Close
Set con = Nothing

%>
</body></html>

Whan You Are Getting Started Follow the following Steps :-

  • You can start database integration into your FrontPage 2000 site today. You don't need any additional software. You don't even have to buy a database program. All you need to create a Web site with database connectivity is FrontPage 2000 and a Web server that is running the FrontPage Server Extensions and ASP (Active Server Pages - see more on this below).
  • Once your FrontPage-based Web site has been published to a server, the pages with database content can be viewed as any other Web page using any Web browser like Internet Explorer or Netscape. No plug-ins or extra software is required.
 
E-mail : sales@virtualsplat.com
Phone : +91-9892413501

Whatsapp Icon +91-9967648641

Whatsapp Icon +91-9967648641