Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.


VB
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
Posted
Comments
CHill60 24-Apr-13 12:00pm    
What is actually in Rs(0) ... I think it might be Null which can't be mapped to a boolean ... I usually use a char(1) not null column for bools (defaulting to N) but you can get around the problem here without changing the database by wrapping the assignment to GetEnrolled in an if-statement
Aleu Philip 24-Apr-13 12:08pm    
R(0) is actually null going to try your suggestion

Steps to do:
1) create and open connection
2) create and open Recordset object
3) while recordset not EOF, read values

VB
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)[^]
 
Share this answer
 
Use this
GetEnrolled = IIf(IsNull(Rs(0).Value), "", Rs(0).Value)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900