Monday, December 17, 2007

How to edit a record in the table (Using SQL command)

How to edit a record in the table (Using SQL command)

S T E P - 1

- We need to create a Connection:

<%

Dim oConn

Set oConn = Server.CreateObject("ADODB.Connection")

oConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")

%>

S T E P - 2

- Use .Execute method to perform the SQL command:

<%

Dim strSQL

strSQL = "UPDATE member SET " & _

"'Email='" & Request.Form("Email") & _

"', Gender='" & Request.Form("Gender") & _

"', AccessLevel='" & Request.Form("AccessLevel") & _

"' WHERE MemberID='" & Request.Form("MemberID") & "';"

oConn.Execute strSQL

oConn.Close

Set oConn = Nothing

%>

How to collect the value of a multiple values from HTML Check Box

How to collect the value of a multiple values from HTML Check Box

S T E P - 1

- When you use some Check Boxes in your HTML form, they are using the same name but different values:

Value1

Value2

Value3

Value4


- When you send the form, the Form collection will generate a multi-value option for the CheckBox.

S T E P - 2

- Now, we can use For..loop to get the multi values:

<%

If Request.form("SameName").Count Then

For intLoop = 1 to Request.form("SameName").Count

Response.write (intLoop & ". " & Request.form("SameName")(intLoop) & "
")

Next

End If

%>


How to make the Cookies more secure

How to make the Cookies more secure

S T E P - 1

- We can setup the Cookies that only your web server can accept it:

<%

Response.cookies("YourCookies").domain = "/www.abc.com/"

%>

S T E P - 2

- The path (or folder) can also use it:

<%

Response.cookies("YourCookies").domain = "/myAsp"

%>

S T E P - 3

- We can set the Cookies which can only transfer to the web server by using the SSL(Secure Sockets Layer) :

<%

Response.cookies("YourCookies").secure = True

%>


How to make the Cookies more secure

How to make the Cookies more secure

S T E P - 1

- We can setup the Cookies that only your web server can accept it:

<%

Response.cookies("YourCookies").domain = "/www.abc.com/"

%>

S T E P - 2

- The path (or folder) can also use it:

<%

Response.cookies("YourCookies").domain = "/myAsp"

%>

S T E P - 3

- We can set the Cookies which can only transfer to the web server by using the SSL(Secure Sockets Layer) :

<%

Response.cookies("YourCookies").secure = True

%>


How to use the information to generate a HTML Select control

How to use the information to generate a HTML Select control

S T E P - 1

- We can open a Connection and RecordSet:

<%

Const adOpenKeyset = 1, adLockReadOnly =1

Dim oConn

Dim oRs

Set oConn = Server.CreateObject("ADODB.Connection")

oConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")

Set oRs = Server.CreateObject("ADODB.Recordset")

%>

S T E P - 2

- We try to search a male member (Mem Id = 01):

<%

strMemID="01"

strSQL = "SELECT * FROM Member WHERE (MemberID='" & strMemID & "');"

oRs.Open strSQL, oConn, adOpenKeyset, adLockReadOnly

If oRs.RecordCount <> 0 then

strRecMemGender = oRs("Gender")

Else

Response.write("Record Not Found!")

Response.End < color="red" size="+1">'If the record not found, we stop to generate the HTML form

End If

oRs.Close

Set oRs = Nothing

oConn.Close

Set oConn = Nothing

%>

S T E P - 3

- We use the data that get from the database to generate the HTML Select control:

How to change local identifiers that define the webserver's locale.

How to change local identifiers that define the webserver's locale.

- Normally, the ASP program will use the information of webserver's local identifiers, which included language, country, culture, and conventions.

- Session object has one property that can allow us to change the local identifiers - LCID:

<%

Session.LCID = 1033 'Set LCID for standard US english

Response.write ("The format date (standard US english) is " & Now() & "
")

Session.LCID = 1049 'Set LCID for Russian

Response.write ("The format date (Russian) is " & Now() & "
")

%>



How to let your ASP program change the languange code

How to let your ASP program change the languange code

- Session object has one property that allows us to change the languange code - CodePage:

<%

Session.Codepage = 1252 '1252 = Western Alphabet (iso-8859-1)

%>

How to get all information in the Session object

How to get all information in the Session object

S T E P - 1

- The Session object has two object collections - Contents and Staticobjects:

- Session.Contents includes all variables that are no created by the :

<%

Dim Item

For Each Item in Session.Contens

Response.write(Item & "= " & Session.Contents(Item) & "
")

Next

%>

S T E P - 2

- Session.Staticobjects included all objects created by the :

<%

Dim Item

For Each Item in Session.staticobjects

Response.write(Item & "= " & Session.staticobjects(Item) & "
")

Next

%>

How to detect the web browser that can support Cookies

How to detect the web browser that can support Cookies

- We can try to send a Cookies to the web browser.

- If the browser cannot support the Cookies, we will also need to avoid the system from displaying the Error message.

<%

On Error Resume Next

If IsEmpty(Session("Testing")) Then

Response.write("No support Cookies")

Else

Response.write("Support Cookies")

End If

%>

How to avoid visitor from using the Application when we make some modifications on the Application

How to avoid visitor from using the Application when we make some modifications on the Application

- We can use the Lock method to avoid the visitor from using the Application:

<%

Appplication.Lock

Application("count") = Application("count") + 1

Application.Unlock

%>

How to create a simple search engine

How to create a simple search engine

S T E P - 1

- We need a search form in HTML format:

S T E P - 2

- We can create a ASP page to show the search result.

- First, we create a FileSystemObject, and use it to get all files in the current folder:

<%

Dim fSys, objFolder, objTxtStream

Dim blnFileFound

blnFileFound = "false"

Set fSys = CreateObject("Scripting.FileSystemObject")

Set objFolder = fSys.GetFolder(Server.MapPath(".")) < color="red" size="+1">'Get the current folder object

%>

S T E P - 3

- Use the objFolder object to get all files in the current folder:

<%

For Each objFile in objFolder.Files

Set objTxtStream = fSys.OpenTextFile(objFile.Path,1)

If Not objTxtStream.AtEndOfStream then < color="red" size="+1">'If Not empty file

strFileContents = objTxtStream.ReadAll

objTxtStream.Close

If InStr(1, strFileContents, Request.form(("SearchKey")), 1) Then

Response.Write "Current folder/" & file_path & _

""">" & objFile.Name & "
"

blnFileFound = "True"

End If

End If

Next

If blnFileFound = "false" Then

Response.write "File Not found give a different search criteria"

End If

Set objFolder = Nothing

Set fSys = Nothing

%>

This is the search result:


How to format the date to prefix the month or day with a zero

How to format the date to prefix the month or day with a zero

S T E P - 1

- We use some techniques to do it.

- First, add a zero in each number. For example:

"0" & Month(Now())

The output will be:

Jan 01

Feb 02

Mac 03

Apr 04

May 05

Jun 06

Jul 07

Aug 08

Sep 09

Oct 010

Nov 011

Dec 012

S T E P - 2

- We just got the last 2 digits from the output:

Right("0" & Month(Now()),2)

so the output will be:

Jan 01

Feb 02

Mac 03

Apr 04

May 05

Jun 06

Jul 07

Aug 08

Sep 09

Oct 10

Nov 11

Dec 12

<%

d = Right("0" & Month(Now()), 2) & "/" & _

Right("0" & Day(Now()), 2) & "/" & _

Year(Now()) & " " & _

Right("0" & Hour(Now()), 2) & ":" & _

Right("0" & Minute(Now()), 2) & ":" & _

Right("0" & Second(Now()), 2)

Response.Write d

%>


How to use the external function from another ASP file

How to use the external function from another ASP file

S T E P - 1

- We can use the external function from another ASP file.

- First, we need to include the external ASP file.

S T E P - 2

-We create a function in the "addition.asp" file:

<%

Function ADD()

ADD = 1+1

End Function

%>

S T E P - 3

- Now we can use the function in the "addition.asp":

<% =ADD() %>


How to avoid problem when using Apostrophe in a SQL command

How to avoid problem when using Apostrophe in a SQL command

S T E P - 1

- For example, we need to add a text "He's car" by using SQL command.

S T E P - 2

- When you use the SQL Command:

<%

strSQL = "Insert into pComment (Comment) values('He's car... ')"

oConn.Execute strSQL

%>

- This will get problem when you use the Insert command:

S T E P - 3

- How to solve the Apostrophe (') problem by using the CHR() function?

- Below is the solution:

<%

strSQL = "Insert into pComment (Comment) values('He" & chr(39) & "s car... ')"

oConn.Execute strSQL

%>

How to create a Counter

How to create a Counter

S T E P - 1

- We can use Server.CreateObject to create a counter. If your web server has already prebuilt a counter, you not need to do it because all web server users will be using same counter:

<% Set myCounter = Server.CreateObject("MSWC.Counters") %>

S T E P - 2

- We need to initialize the counter:

<%

Dim mailHits

myCounter.Set(mailHits, 0)

%>

S T E P - 3

- Use MailHits to count the visitor.

<%

Counter.Increment(mailHits)

Response.write("You are " & Counter.Get(mailHits) %> & " visitor")

%>


How to count pages that have been opened

How to count pages that have been opened

S T E P - 1

- Page Counter is ASP's standard object.

<%

Dim numHits

Set numHits = Server.CreateObject("MSWC.PageCounter")

%>

S T E P - 2

- We can show the total of hits in the current page:

<%

Response.write ("Number Of Hits - " & numHits.Hits())

%>


How to delete a folder in the web server

How to delete a folder in the web server

S T E P - 1

- We need to use the FileSystemObject object:

<%

Dim fSys, objNewFolder

Set fSys = CreateObject("Scripting.FileSystemObject")

%>

S T E P - 2

- Now, we can use the server.mappath(".") to get the web server's current folder

- We can create a new folder in the current folder by using DeleteFolder method.

<%

Set objNewFolder = fSys.DeleteFolder(server.mappath(".") & "\myFolder")

Response.write("Process Deleter Folder")

Set objNewFolder = Nothing

Set objFileSys = Nothing

%>

How to move or copy a folder in the web server

How to move or copy a folder in the web server

S T E P - 1

- We need to use the FileSystemObject object:

<%

Dim fSys, objNewFolder

Set fSys = CreateObject("Scripting.FileSystemObject")

%>

S T E P - 2

- Now, we can use the server.mappath(".") to get the web server's current folder

- We can move folder in the current folder by using MoveFolder method.

<%

Set objNewFolder = fSys.MoveFolder(server.mappath(".") & "\myFolder", server.mappath("..") & "\myFolder")

Response.write(objNewFolder.path)

Set objNewFolder = Nothing

Set objFileSys = Nothing

%>

S T E P - 3

- Now, we can use the server.mappath(".") to get the web server's current folder.

- We can move folder in the current folder by using CopyFolder method.

<%

Set objNewFolder = fSys.CopyFolder(server.mappath(".") & "\myFolder", server.mappath("..") & "\myFolder")

Response.write(objNewFolder.path)

Set objNewFolder = Nothing

Set objFileSys = Nothing

%>


How to create a folder in the web server

How to create a folder in the web server

S T E P - 1

- We need to use the FileSystemObject object:

<%

Dim fSys, objNewFolder

Set fSys = CreateObject("Scripting.FileSystemObject")

%>

S T E P - 2

- Now, we can use the server.mappath(".") to get the web server's current folder

- We can create a new folder in the current folder by using CreateFolder method.

<%

Set objNewFolder = fSys.CreateFolder(server.mappath(".") & "\myFolder")

Response.write(objNewFolder.path)

Set objNewFolder = Nothing

Set objFileSys = Nothing

%>

How to copy a text to another folder

How to copy a text to another folder

S T E P - 1

- We need to use the FileSystemObject object:

<%

Dim fSys

Set fSys = CreateObject("Scripting.FileSystemObject")

%>

S T E P - 2

- We can use the server.mappath(".") to get the webserver's current folder.

- We use the MoveFile method to move a file to another folder.

<%

fSys.MoveFile server.mappath(".") & "\myFile.txt", "C:\"

response.write("Process copy file")

Set fSys = Nothing

%>


How to copy a text to another folder

How to copy a text to another folder

S T E P - 1

- We need to use the FileSystemObject object:

<%

Dim fSys

Set fSys = CreateObject("Scripting.FileSystemObject")

%>

S T E P - 2

- We can use the server.mappath(".") to get the webserver's current folder.

- So, we save the text file to the upper folder - server.mappath(".."),

- Now we can use the CopyFile method to copy the file to the upper folder.

<%

fSys.CopyFile server.mappath(".") & "\myFile.txt", server.mappath("..") & "\"

response.write("Process copy file")

Set fSys = Nothing

%>


How to delete the text file in the web server

How to delete the text file in the web server

S T E P - 1

- We need to use the FileSystemObject object:

<%

Const ForReading = 1, ForAppending = 8 'Set the iomode

Dim fSys

Set fSys = CreateObject("Scripting.FileSystemObject")

%>

S T E P - 2

- We can use the server.mappath(".") to get the webserver's current folder.

- After that, use the Deletefile method to delete the file that we selected.

<%

fSys.DeleteFile(server.mappath(".") & "\myFile.txt")

Response.write("Process delete file")

Set fSys = Nothing

%>

How to open a text file on the web server and write data into this file (Using TextStream)

How to open a text file on the web server and write data into this file (Using TextStream)

S T E P - 1

- We need to use the FileSystemObject object:

<%

Const ForReading = 1, ForAppending = 8 'Set the iomode

Dim fSys, objF, objText

Set fSys = CreateObject("Scripting.FileSystemObject")

%>

S T E P - 2

- We can use the server.mappath(".") to get the webserver's current folder.

- After that, use the GetFile method to get a File Object.

<%

Set objF = fSys.GetFile(server.mappath(".") & "\myFile.txt")

Set objText = objF.OpenAsTextStream(ForAppending, 0)

'0 = Using ASCII format

'-1 = Using Unicode format

'-2 = Using system default format

objText.writeLine("Hello Word")

objText.Close

Set objF = Nothing

Set fSys = Nothing

%>


How to open a text file on the web server and read it

How to open a text file on the web server and read it

S T E P - 1

- We need to use the FileSystemObject object:

<%

Const ForReading = 1, ForAppending = 8 'Set the iomode

Dim fSys, f

Set fSys = CreateObject("Scripting.FileSystemObject")

%>

S T E P - 2

- Now, we need to get the web server's current folder.

- We can use the server.mappath(".") to get it.

- So, we can open the text file in the web server using OpenTextFile method.

<%

Set objOpenFile = fSys.OpenTextFile(server.mappath(".") & "\myFile.txt", ForReading)

Response.write(objOpenFile.ReadAll)

Set fSys = Nothing

%>

How to create a text file in the web server

How to create a text file in the web server

S T E P - 1

- We need to use the FileSystemObject object to get the information:

<%

Dim fSys, f

Set fSys = CreateObject("Scripting.FileSystemObject")

%>

S T E P - 2

- Now, we need to get the web server current folder.

- We can use the server.mappath(".") to get it.

- So, we can create a text file in the web server by using CreateTextFile method.

<%

Set objNewFile = objFileSys.CreateTextFile(server.mappath(".") & "\myFile.txt")

Set objNewFile = Nothing

Set objFileSys = Nothing

%>

How to get system folder on your computer

How to get system folder on your computer

S T E P - 1

- We need to use the FileSystemObject object to get the information:

<%

Dim fSys, f

Set fSys = CreateObject("Scripting.FileSystemObject")

%>

S T E P - 2

- Now we can get the system folder by using the GetSpecialFolder method:

<%

For i = 0 to 1

Set f = fSys.GetSpecialFolder(i)

Response.write ("

")

Next

%>

" & f & "" & f.size & "" & f.name & "


How to check the C drive if it still has more space

How to check the C drive if it still has more space

S T E P - 1

- We need to use the FileSystemObject object to get the information:

<%

Dim fSys, oDrive

Set fSys = CreateObject("Scripting.FileSystemObject")

%>

S T E P - 2

-In the FileSystemObject, we can find a Drives properties. This properties can return all drive information:

<%

Set oDrive = fSys.GetDrive("c:")

Response.write("Free space on C: is " & oDrive.freespace)

%>


How detect your CD-ROM drive letter

How detect your CD-ROM drive letter

S T E P - 1

- We need to use the FileSystemObject object to get the information:

<%

Dim fSys, oDrive

Set fSys = CreateObject("Scripting.FileSystemObject")

%>

S T E P - 2

-In the FileSystemObject, we can find a Drives properties. This properties can return all drive information:

<%

Set oDrive = fSys.Drives

For Each Item in oDrive

If Item.DriveType = 4 Then

Response.write("Your CD-ROM drive is " & Item.DriveLetter)

End If

Next

%>


How to delete a record in database

How to delete a record in database

S T E P - 1

- Firstly, we will need to create a RecordSet:

<%

Const adOpenKeyset = 1, adLockPessimistic = 2

Dim oConn

Dim oRs

Set oConn = Server.CreateObject("ADODB.Connection")

oConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")

Set oRs = Server.CreateObject("ADODB.Recordset")

oRs.Open "SELECT * FROM member WHERE MemberID='" & strMemberID & "';", oConn, adOpenKeyset, adLockPessimistic 'Open "Member"table and found a single record based on the value of strMemberID

%>

S T E P - 2

- We need to check the record if it is existed or not.

- If the RecordCount = 0 , that means the record is not existed in the database:

<%

If oRs.RecordCount = 0 Then

Response.Write("The record is not found")

Response.End

End If

%>

S T E P - 3

- If the RecordCount <> 0 , we continue the Delete function:

<%

If oRs.RecordCount = 0 Then

Response.Write("The record is not found")

Response.End

Else

oRs.Delete 'Delete the record

End If

oRs.Close

Set oRs = Nothing

oConn.Close

Set oConn = nothing

%>

How to find a record by using RecordSet

How to find a record by using RecordSet

S T E P - 1

- We need to create a RecordSet and Connection.

<%

Const adOpenKeyset = 1, adLockPessimistic = 2

Dim oConn

Dim oRs

Set oConn = Server.CreateObject("ADODB.Connection")

oConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")

Set oRs = Server.CreateObject("ADODB.Recordset")

oRs.Open "Member", oConn, adOpenKeyset, adLockPessimistic 'Open "Member"table

%>

S T E P - 2

- We use Find method to search a record:

<%

oRs.Find "MemberID='YourID'", 0, adSearchForward

'Search a record that the member id is 'YourID', and search form first record.

If oRs.EOF Then 'If the EOF is TRUE, that means the record not found

Response.write "Record not found"

Else

Response.write oRs("Email")

End If

oRs.Close

Set oRs = Nothing

oConn.Close

Set oConn = nothing

%>


How to edit a record in the RecordSet

How to edit a record in the RecordSet

S T E P - 1

- We need to create a RecordSet:

<%

Const adOpenKeyset = 1, adLockPessimistic = 2

Dim oConn

Dim oRs

Set oConn = Server.CreateObject("ADODB.Connection")

oConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")

Set oRs = Server.CreateObject("ADODB.Recordset")

oRs.Open "SELECT * FROM member WHERE MemberID='" & strMemberID & "';", oConn, adOpenKeyset, adLockPessimistic 'Open "Member"table and found a single record based on the value of strMemberID

%>

S T E P - 2

- We need to check the record if it is existed or not.

- If the RecordCount = 0 , that means the record is not existed in the database:

<%

If oRs.RecordCount = 0 Then

Response.Write("The record is not found")

Response.End

End If

%>

S T E P - 3

- If the RecordCount <> 0 , we continue the edit function:

<%

If oRs.RecordCount = 0 Then

Response.Write("The record is not found")

Response.End

Else

oRs("MemberID") = "Your New ID"

oRs("Password") = "Your New Password"

oRs("Email") = "Your New Email"

End If

%>

S T E P - 4

- Finally, you need to update the table, if not, the new record will not be changed.

<%

If oRs.RecordCount = 0 Then

Response.Write("The record is not found")

Response.End

Else

oRs("MemberID") = "Your New ID"

oRs("Password") = "Your New Password"

oRs("Email") = "Your New Email"

oRs.Update

End If

%>

S T E P - 5

- Dont forget to close the RecordSet and Connection.

<%

oRs.Close

Set oRs = Nothing

oConn.Close

Set oConn = Nothing

%>

How to add a record by using RecordSet

How to add a record by using RecordSet

S T E P - 1

- We need to create a RecordSet and use .AddNew method to add a new record.

Const adOpenKeyset = 1, adLockPessimistic = 2

Dim oConn

Dim oRs

Set oConn = Server.CreateObject("ADODB.Connection")

oConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")

Set oRs = Server.CreateObject("ADODB.Recordset")

oRs.Open "Member", oConn, adOpenKeyset, adLockPessimistic 'Open "Member"table

oRs.AddNew 'Start add new record, the record pointer will be point to the end of table

S T E P - 2

- Now you can assign the value to the table:

oRs("MemberID") = "Your ID"

oRs("Password") = "Your Password"

oRs("Email") = "Your Email"

S T E P - 3

- Finally, you need to update the table, if not, the new record will not be added into the database.

oRs.Update

S T E P - 4

- Dont forget close the RecordSet and Connection.

oRs.Close

Set oRs = Nothing

oConn.Close

Set oConn = Nothing


How to add a record to the table (Using SQL command)

How to add a record to the table (Using SQL command)

S T E P - 1

- We need to create a Connection:

Dim oConn

Set oConn = Server.CreateObject("ADODB.Connection")

oConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")

S T E P - 2

- Use .Execute method to perform the SQL command.

Dim strSQL

strSQL = "Insert into member" & _

"(MemberID, Password, AccessLevel) " & _

"values('" & strMemberID & _

"','" & strPassword & _

"','" & strAccessLevel & "')"

oConn.Execute strSQL

How to check the record if it is already in the database

How to check the record if it is already in the database

S T E P - 1

- We use the SQL to search the record based on some decisions. For example:

Dim oConn

Dim oRs

Set oConn = Server.CreateObject("ADODB.Connection")

oConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")

Set oRs = oConn.Execute("SELECT * FROM member WHERE MemberID='" & strMemberID & "';")

' We search a single member record based on the MemberID

S T E P - 2

- We used the SQL command to filter the RecordSet.

- If the RecordCount = 0 , that means the record is not existed in the database:

If oRs.RecordCount = 0 Then

Response.Write("The record is not found")

End If


How to detect the RecordSet if it is empty

How to detect the RecordSet if it is empty

S T E P - 1

- We can use 2 methods to detect the RecordSet is empty.

- First method is using BOF(Beginning Of File) and EOF(End Of File).

Dim oConn

Dim oRs

Set oConn = Server.CreateObject("ADODB.Connection")

oConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")

Set oRs = oConn.Execute("SELECT * FROM Member")

If oRs.BOF and oRs.EOF Then

Response.Write("The table is empty")

End If

S T E P - 2

- Second method is to use the RecordCount properties:

- If the RecordCount = 0 , that means no record in the table:

Dim oConn

Dim oRs

Set oConn = Server.CreateObject("ADODB.Connection")

oConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")

Set oRs = oConn.Execute("SELECT * FROM Member")

If oRs.RecordCount = 0 Then

Response.Write("The table is empty")

End If

How to get the total of records in the table

How to get the total of records in the table

S T E P - 1

- We have a "member" table and we need to show the total of member in the table.

- Now, we create a RecordSet to open the member table.

<%

Const adOpenKeyset = 1, adLockPessimistic = 2

Dim oConn

Dim oRs

Set oConn = Server.CreateObject("ADODB.Connection")

oConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("cp.mdb")

Set oRs = Server.CreateObject("ADODB.Recordset")

oRs.Open "member", oConn, adOpenKeyset, adLockPessimistic

%>

S T E P - 2

- we can use the RecordCount to get the value.

- Finally, please close the recordSet and Connection.

<%

Response.write "

Total Members : " & oRs.RecordCount & "
"

oRs.Close

oConn.Close

Set oRs = Nothing

Set oConn = Nothing

%>

How to create a RecordSet

How to create a RecordSet

S T E P - 1

- First, we need a connection.

Dim oConn

Set oConn = Server.CreateObject("ADODB.Connection")

oConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")

S T E P - 2

- We can use a SQL command to search the information in a database, and create it to a RecordSet.

Dim oRs

Set oRs = oConn.Execute("SELECT * FROM Member")

S T E P - 3

- We also can use the Server.CreateObject to create a RecordSet directly.

Dim oRs

Set oRs = Server.CreateObject("ADODB.Recordset")

oRs.Open "Member", oConn, , , adComdTable 'Open "Member"table

S T E P - 4

- After finished using the RecordSet, we will need to close it:

oRs.Close

Set oRs = Nothing