Download presentation
Presentation is loading. Please wait.
Published byTobias Lane Modified over 9 years ago
1
Internet Programming ASP 30.06.20101 Sara Shahzad Dept. of Computer Science UOP
2
ASP Database Connection ASP can be used to connect to Microsoft Access or SQL Server database. An ASP script can contain Structured query language (SQL) statements like insert, delete and update. For example: SELECT * FROM myTable WHERE myValue = 'myValue' INSERT INTO myTable (value1) VALUES ("myValue") 17.06.2010 Sara Shahzad Dept. of Computer Science UOP 2
3
ASP database Connection A database connection is done via a connection string in the ASP source code. two ways – using a data source name (DSN) – using a DSN-Less connection string, which can use either the Server.MapPath method or physical pathname to locate the database. 17.06.2010 Sara Shahzad Dept. of Computer Science UOP 3
4
using a data source name (DSN) example connection string using a DSN: <% dim strConnection, dbase # 'Create string with the name of the data source strConnection = "MyDSN" Set dbase = Server.CreateObject("ADODB.Connection") 'Open database dbase.Open strConnection, "user", "password" %> 17.06.2010 Sara Shahzad Dept. of Computer Science UOP 4
5
Configuring the connection DSN's are created using the ODBC data source administrator. This can be found in your system32 folder or within control panel. When you set up a data source name you are required to input the data source name, plus the database that it connects to and the path of that database. A user ID and password are also necessary, which is what will be within the two "", "" parameters in the dbase.Open line. 17.06.2010 Sara Shahzad Dept. of Computer Science UOP 5
6
DSN-less connection <% DIM objConn Set objConn = Server.CreateObject("ADODB.Connection") objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath ("/mydatabase.mdb") & ";“ ` ConnectionString and Server.MapPath should be on the same line objConn.Open %> Server.MapPath maps the path back to web server root that the pages are running on, via the directory you have specified. 17.06.2010 Sara Shahzad Dept. of Computer Science UOP 6
7
VBScript Class example (vbclass.html) Option Explicit Class student private name public property let firstname(fn) name=fn end property 17.06.2010 Sara Shahzad Dept. of Computer Science UOP 7
8
public property get firstname() firstname=name end property public function ToString() toString=name end function end class 17.06.2010 Sara Shahzad Dept. of Computer Science UOP 8
9
Sub cmdButton_OnClick() Dim s, s1 ' declare object reference Set s = New student ' instantiate person object With s.firstname = Document.Forms(0).txtBox1.Value Call MsgBox(.ToString( )) End With End Sub Sara Shahzad Dept. of Computer Science UOP 9
10
Enter first name 17.06.2010 Sara Shahzad Dept. of Computer Science UOP 10
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.