- Database support -

Hvornår skal jeg bruge hvad?

Som standard bruger man normalt Connection object, da det giver den korteste kode.

Når den samme eller lignende query bliver kaldt mange gange med mindre ændringer som for eksempel en parameter bør du bruge Command object, da det giver serveren mulighed for at cache dine SQL kald og forbedre ydelsen meget.

At åbne et recordset kan ikke anbefales.

Først skal du vælge en connection string (dataforbindelse).

Skab en forbindelse og luk den efter brug

<%
  Dim objConnection, strConnect
  <!-- #include file="connect.inc" -->
  Set objConnection = Server.CreateObject("ADODB.Connection")
  objConnection.Open strConnect
  
  ...her forbinder du til databasen, vælg en mulighed fra nedenstående...

  objConnection.Close
  Set objConnection = Nothing
%>

Connection (lettest)

<%
  strSQL = "INSERT INTO tabel (felt1, felt2) VALUES (værdi1, værdi2)"
  objConnection.Execute(strSQL)
%>

Connection med dataudtræk (returnerer data)

<%
  strSQL = "SELECT * FROM tabel WHERE total = xxx"
  Set objConnection = objConnection.Execute(strSQL)

  Do While Not objConnection.EOF
    Response.Write objConnection.Fields("felt1") & " " & objConnection.Fields("felt2") & "<br/>"
    objConnection.MoveNext
  Loop
%>

Command Execute (cacher dit kald, hurtig hvis du kalder flere gange)

<%
  Set objCommand = Server.CreateObject("ADODB.Command")
  Set objCommand.ActiveConnection = objConnection
  objCommand.CommandText = strSQ
  objCommand.CommandType = adCMDText
  objCommand.Execute
  Set objCommand = Nothing
%>

Recordset (add) (langsomt, har dog visse avancerede muligheder)

<%
  Recordset.AddNew
  Recordset("Felt") = "En ny værdi"
  Recordset.Update
%>

Recordset (show) (som ovenstående, med dataudtræk)

<%
  Dim objRec
  Set objRec = Server.CreateObject("ADODB.Recordset")

  objRec.Open "Tabel", objConnection, 0, 1, 2

  Do While Not objRec.EOF
    Response.Write objRec("Felt") & "<br/>"
    objRec.MoveNext
  Loop

  objRec.Close
  Set objRec = Nothing
%>

Se ydeligere support til de forskellige databaser under /support/database.

Link Beskrivelse
Microsoft Forklaring om forskellige ADO metoder.

Referencer

crossfit

"Team CrossFit Copenhagen takker for støtten fra Azero i vores kamp for at nå til CrossFit Games (VM) i Californien i Juli."

Nikolaj Rønnow

2015-01-19T11:02:53+00:00

Nikolaj Rønnow

crossfit
"Team CrossFit Copenhagen takker for støtten fra Azero i vores kamp for at nå til CrossFit Games (VM) i Californien i Juli."
eyeforimage

Azero has been Eye for Image's ISP from the very beginning. It's reassuring to know that they not only have a great array of products, but that we can always get relevant and timely information from their professional support team, by just picking up the phone and talking to someone.

Matt Coyle, Technical Copywriter / Eye for Image ApS

2015-01-20T03:47:24+00:00

Matt Coyle, Technical Copywriter / Eye for Image ApS

eyeforimage
Azero has been Eye for Image's ISP from the very beginning. It's reassuring to know that they not only have a great array of products, but that we can always get relevant and timely information from their professional support team, by just picking up the phone and talking to someone.

Kontakt Azero

Firmainformationer

AzeroCloud ApS
Nørregade 33
8464 Galten
CVR: 38 70 69 93
VAT: DK38706993

Telefon

Telefon: 38 19 50 17
 

Normal telefontid

Man-tor: 9:30-12:00 og 13:00-15:30
Fredag: 9:30-12:00 og 13:00-14:00