Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB6
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
Posted 24-Apr-13 6:35am
Comments
CHill60 at 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 at 24-Apr-13 12:08pm
   
R(0) is actually null going to try your suggestion
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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)[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use this
GetEnrolled = IIf(IsNull(Rs(0).Value), "", Rs(0).Value)
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 280
1 Jochen Arndt 150
2 Kornfeld Eliyahu Peter 120
3 PIEBALDconsult 110
4 Richard MacCutchan 105
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 10 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100