Classic ASP で次のエラーが発生しました。
Microsoft VBScript runtime error '800a01a8'
Object required: 'SqlStatement'
/Data/Database.asp, line 186
行 186 は次のとおりSqlStatement.CommandText = sql
です。
これが私のコードです:
Dim Db, SqlStatement, RS
Set Db = Nothing
Set SqlStatement = Nothing
Set RS = Nothing
' Initialize the database once
Private Sub SqlInitDb()
If isNull(Db) Or varType(Db) = vbEmpty Or IsObject(Db) = False Then
' Create database connection object
Set Db = Server.CreateObject("ADODB.Connection")
' Set connection timeout
Db.ConnectionTimeout = Session("ConnectionTimeout")
' Set command timeout
Db.CommandTimeout = Session("CommandTimeout")
' Open database
Db.Open Session("ConnectionString")
End If
If isNull(SqlStatement) Or varType(SqlStatement) = vbEmpty Or IsObject(SqlStatement) = False Then
' Create a sql statement
Set SqlStatement = Server.CreateObject("ADODB.Command")
' Set opened database as active connection for the SQL statement
SqlStatement.ActiveConnection = Db
End If
End Sub
' Close the database if it is not closed
Private Sub SqlClose()
If Not isNull(SqlStatement) And varType(SqlStatement) <> vbEmpty And IsObject(SqlStatement) = True Then
SqlStatement.ActiveConnection.Close
End If
Set SqlStatement = Nothing
If Not isNull(Db) And varType(Db) <> vbEmpty And IsObject(Db) = True Then
For Each objErr In Db.Errors
response.write("<p>")
response.write("Description: ")
response.write(objErr.Description & "<br>")
response.write("Help context: ")
response.write(objErr.HelpContext & "<br>")
response.write("Help file: ")
response.write(objErr.HelpFile & "<br>")
response.write("Native error: ")
response.write(objErr.NativeError & "<br>")
response.write("Error number: ")
response.write(objErr.Number & "<br>")
response.write("Error source: ")
response.write(objErr.Source & "<br>")
response.write("SQL state: ")
response.write(objErr.SQLState & "<br>")
response.write("</p>")
Next
Db.Close()
Set Db = Nothing
End If
End Sub
' Insert a user to the database
Public Function InsertUser(ByVal userObj)
If isNull(userObject) Or varType(userObject) = vbEmpty Then
InsertUser = -1
Exit Function
End If
Call SqlInitDb()
Set RS = Server.CreateObject("ADODB.Recordset")
Dim sql
sql = "INSERT INTO users(Firstname,Surname) VALUES ('"&userObj.getFirstname()&"','"&userObj.getSurname()&"')"
SqlStatement.CommandText = sql
SqlStatement.CommandType = 1
' Run the insert statement
SqlStatement.Execute
InsertUser = Err.Number
Call SqlClose()
End Function
SqlStatement は明らかにオブジェクトなのでわかりません。
ありがとう