Shadow Blade
Morrowland Presents Apron Tutorials
game - design - multimedia - web - programming - tutorials - There are currently viewers visiting Apron Tutorials.
   
 
TECHNICAL
GRAPHICAL
SOUND
GAME
WEB
ARTICLE
TOOL
PROJECT
 
 NEWS

  news

  history


 TECHNICAL TUTORIALS

  opengl

  direct3d

  c/c++

  visual basic

  java

  c#


 WEB TUTORIALS

  html

  dhtml

  asp

  php


 IMAGE EDITING

  photoshop

  draw sketch


 3D MODELING

  3d studio


 PROJECTS

  shadow blade

  game environment

  virtual 3d guide

  billy blue flame


 DEMOS

  win32 api


 ARTICLES

  general

  opengl


 COMMUNITY

  about us

  credit

  contact






DATABASE AND ASP
When you want to store some data, either how many viewers your page have registered, or you want to make guestbooks or forums, you have to store the data. By using database you get well structured data, that you easily can access. In this tutorial I will show how you can connect, read, update and write to a mysql database.



The connection

In order to connect to a mysql database you have to know the host, the username and password for editing the database and the name of the database. The connection code is given below:

Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
          "Data Source=" & Server.Mappath("MyDb.mdb") & ";"



Disconnect

When you have have updated, inserted or read the recordsset you wanted, it is important to close your connection. The disconnect code is given below:

objConn.Close
Set objConn = Nothing



Get data

When you want to get data from a database, you use sql statements. The sql statement then return a recordset which you may list. In my database I have a table called 'Users' where I have stored all the users registered in my site, in a Name colomn. To get hold of the users I first use a sql statement and then I use php scripting to go true the recordset.


const strSQL = "SELECT * FROM Users"
Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn

'Loop through the Recordset
Do While Not objRS.EOF

	Response.Write(objRS.fields("Name"))
  objRS.MoveNext

Loop




Insert Data

When you want to insert data from a database, you also use sql statements. By calling the sql statement below you get inserts a new name into the Users table:

strSQL = "INSERT INTO Users (Name) VALUES ( 'a new name' )"

Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn




Delete Data

When you want to delete data from a database, you also use sql statements. By calling the sql statement below you delete a new name from the Users table:

strSQL = "DELETE FROM Users WHERE Name LIKE 'a new name'"

Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn




Update Data

When you want to update data from a database, you also use sql statements. By calling the sql statement below you replace the name 'Jack' with 'Jackson' from the Users table:

strSQL = "UPDATE Users SET Name = 'Jackson' WHERE Name LIKE 'Jack'"

Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn



PROJECT DESCRIPTION
Category Programming with ASP
Author Tommy Johannessen





Ronny André Reierstad
Morrowland All rights reserved Morrowland © 2002 Apron Tutorials

 LINKS

  morrowland home



 GAME DEVELOPEMENT

  nvidia

  gamedev

  polycount


 PROJECTS

  shadow blade

  game environment

  virtual 3d guide

  billy blue flame


 MATH AND PHYSICS

  mathworld

  physicsworld







PLEASE LINK TO


  All rights reserved Morrowland © 2007  
Ronny André Reierstad