---
title: "ExecuteSQL"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/38194-executesql"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "rymdknark"
published: "2001-06-15T11:44:00.000Z"
updated: "2001-06-15T11:44:00.000Z"
replies: 0
views: 822
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/38194-executesql"
---

# ExecuteSQL

## #1 — rymdknark, 2001-06-15T11:44Z

Function ExecuteSQL(ByVal sSql, ByVal vCn)
	Dim oRs, oCn, sTokens

	sTokens	= Split(sSql)
	If (Ubound(sTokens) = 0) Then Exit Function

	Set oCn	= Server.CreateObject("ADODB.Connection")
	oCn.Open vCn

	If (InStr("INSERT UPDATE DELETE", UCase(sTokens(0)))) Then
		oCn.Execute sSql
	Else
		Set oRs	= Server.CreateObject("ADODB.Recordset")
			
		oRs.CursorLocation = 3
		oRs.Open sSql, oCn, 0, 4
		Set oRs.ActiveConnection = Nothing

		Set ExecuteSQL = oRs

	End If

	oCn.Close
	Set oCn	= Nothing

End Function

Permalänk: https://www.webforum.nu/p/38194

---

Tråden på webben: https://www.webforum.nu/amne/asp/38194-executesql
