我正在为MS Access使用以下SQL语句:
Public Function GetSectionID(ByVal Course As String, ByVal YrLvl As Integer, ByVal Section As String) As Integer
If Connection.State = ConnectionState.Closed Then
Connection.Open()
End If
Dim sql As String = "SELECT SectionID FROM tblCourses WHERE Course = '" & Course & "' AND (YrLevel = " & YrLvl & " AND Section = '" & Section & "')"
Dim comd As New OleDbCommand(sql, Connection)
Dim reader As OleDbDataReader = comd.ExecuteReader
Dim int As Integer = -1
If reader.HasRows Then
While reader.Read
int = CInt(reader.Item(0))
Exit While
End While
End If
Return int
End Function
当我执行程序时,它返回错误:
IErrorInfo.GetDescription因E_FAIL(0x80004005)而失败。
可能出了什么问题?