运行时错误'94'无效使用Null [英] Run-time error '94' Invalid use of Null
本文介绍了运行时错误'94'无效使用Null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
需要有关学生表结构的建议。对于sql server 2005的注册列(数据类型)的兴趣。我还需要使用我的函数声明的数据类型的建议。我的登记列目前有位数据类型。我得到的错误可能是问题。
公共 功能 GetEnrolled()作为 Boolean
如果 Rs.State = adStateOpen 那么 Rs.Close
sql = SELECT Students.Enrolled From Students WHERE Students.sID ='& vOldIDNumber& '和students.yrlevel ='& voidYearlevel& '和students.scourse ='& voidCourse& '和semester ='& voidSem& '
Rs.Open sql,RSconn
如果 不 Rs.EOF 那么
GetEnrolled = Rs ( 0 )。值
结束 如果
结束 功能
解决方案
要做的步骤:
1)创建并打开连接
2)创建并打开Recordset对象
3)虽然记录集不是EOF,但读取值
Dim oConn As ADODB.Connection
Dim sConn As 字符串
Dim oRst As ADODB.Recordset
Dim sSQL As 字符串
sConn = 您的连接
设置 oConn = 新 ADODB.Connection
oConn.Open sConn
Set oRst = New ADODB.Recordset
sSQL = 您的查询
rstEmployees.Open sSQL,oConn,adOpenStatic, adLockOptimistic,adCmdTable
不 oRst.EOF
MsgBox oRst.Fields( 0 )。值
.MoveNext
循环
查看更多:
Open Method(ADO记录集) ) [ ^ ]
打开和关闭方法示例(VB) [ ^ ]
MoveFirst,MoveLast,MoveNext和MovePrevious Methods Example(VB) [ ^ ]
使用此
GetEnrolled = IIf(IsNull(Rs(0).Value),,Rs(0).Value)
Need advice on the structure of students table..interest on enrolled column(datatype) for sql server 2005. I also need advice on the use of the datatype for which my function is declared. My enrolled column currently has bit datatype. Am getting the error above what could be the problem.
Public Function GetEnrolled() As Boolean
If Rs.State = adStateOpen Then Rs.Close
sql = " SELECT Students.Enrolled From Students WHERE Students.sID='" & vOldIDNumber & "' and students.yrlevel='" & voidYearlevel & "' and students.scourse='" & voidCourse & "' and semester='" & voidSem & "'"
Rs.Open sql, RSconn
If Not Rs.EOF Then
GetEnrolled = Rs(0).Value
End If
End Function
解决方案
Steps to do:
1) create and open connection
2) create and open Recordset object
3) while recordset not EOF, read values
Dim oConn As ADODB.Connection Dim sConn As String Dim oRst As ADODB.Recordset Dim sSQL As String sConn = "Your connection" Set oConn = New ADODB.Connection oConn.Open sConn Set oRst = New ADODB.Recordset sSQL = "your query" rstEmployees.Open sSQL, oConn, adOpenStatic, adLockOptimistic, adCmdTable Do While Not oRst.EOF MsgBox oRst.Fields(0).Value .MoveNext Loop
See more:
Open Method (ADO recordset)[^]
Open and Close Methods Example (VB)[^]
MoveFirst, MoveLast, MoveNext, and MovePrevious Methods Example (VB)[^]
Use this
GetEnrolled = IIf(IsNull(Rs(0).Value), "", Rs(0).Value)
这篇关于运行时错误'94'无效使用Null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文