Visa ett inlägg
Oläst 2008-04-14, 10:20 #2
Jares avatar
Jare Jare är inte uppkopplad
Nykomling
 
Reg.datum: Mar 2008
Inlägg: 46
Jare Jare är inte uppkopplad
Nykomling
Jares avatar
 
Reg.datum: Mar 2008
Inlägg: 46
Vad får du för felmeddelande då?

Jag använder mig alltid av en funktion istället

Functions.asp
Kod:
Function ExecuteSQL(strSQL)
	if(TypeName(dbConnection)<>"Connection") Then
 OpenConnection()
	End if
	
	QueryCounter = QueryCounter +1
	If InStr(1, strSQL, "UPDATE", 1) Or InStr(1, strSQL, "EXEC", 1) Or InStr(1, strSQL, "DELETE", 1) Or InStr(1, strSQL, "INSERT", 1) Then
 dbConnection.Execute (strSQL), , 128
	Else
 Set ExecuteSQL = dbConnection.Execute(strSQL)
	End If
End Function

Public Function GetDbRows(query)
	if(TypeName(dbConnection)<>"Connection") Then
 OpenConnection()
	End if
	
	QueryCount = QueryCount + 1
	Set rs = dbConnection.Execute(query)
 If rs.Eof Then
 	GetDbRows = Null
 Else
 	GetDbRows = rs.GetRows()
 End If
	rs.Close : Set rs = Nothing
End Function

Function OpenConnection()
	if(TypeName(dbConnection)<>"Connection") Then 
 Set dbConnection = Server.CreateObject("ADODB.Connection")	
 dbConnection.ConnectionTimeout = DB_CONNECTIONTIMEOUT
 dbConnection.CommandTimeout = DB_COMMANDTIMEOUT
 dbConnection.Open "Driver={MySQL ODBC 3.51 Driver}; Server=" & DB_SERVER & "; Port=" & DB_PORT & "; Database=" & DB_NAME & "; User=" & DB_USERNAME & "; Password=" & DB_PASSWORD & "; Option=3;"
	End If
End Function

Function CloseConnection()
	If(TypeName(dbConnection)="Connection") Then
 dbConnection.Close : Set dbConnection = Nothing
	End if
End Function
Sedan används funktionerna:
Kod:
<!-- #include virtual="/_inc/Functions.asp" -->
<%
Set rs = ExecuteSQL("SELECT * FROM bgcolor")
%>
Om du vill köra en INSERT, UPDATE eller DELETE:
Kod:
<!-- #include virtual="/_inc/Functions.asp" -->
<%
ExecuteSQL("DETELE FROM bgcolor")
%>
Om du hämtar flera poster skapar du en array:
Kod:
<!-- #include virtual="/_inc/Functions.asp" -->
<%
arrPoster = getDbRows("SELECT farg, nummer FROM bgcolor")

If IsArray(arrPoster) Then
   For iPost = 0 To UBound(arrPoster,2)
      ' LOOPAR UT POSTER
      Farg = arrPoster(0,iPost)
      Nummer = arrPoster(1,iPost)

      Response.Write("FÄRGEN ÄR " & Farg & " OCH HAR FÄRGNUMMER " & Nummer & ".")
   Next
Else
   Response.Write("HITTADE INGA POSTER")
End If
%>
Lycka till
Jare är inte uppkopplad   Svara med citatSvara med citat