E
Edwinah63
Hi guys,
i have a collection containing the values and metadata about a current
record.
i build it by looping through the recordset as follows:
Public Function NoNull(ByVal Value As Object) As String
Return IIf(IsDBNull(Value), "", Value)
End Function
Public Function LoadFields(ByRef rs As ADODB.Recordset) As Collection
'returns fields of a single record
Dim fldCol As Collection
Dim p As PType
Dim i As Integer
fldCol = New Collection
Try
fldCol = New Collection
With rs
For i = 0 To .Fields.Count - 1
p = New PType
p.FieldName = .Fields(i).Name
p.Datatype = .Fields(i).Type
p.varValue = NoNull(.Fields(i).Value) '*** dies
here when no value
p.intLen = .Fields(i).DefinedSize()
fldCol.Add(p, p.FieldName)
Next i
End With
Catch e As Exception
Debug.WriteLine(e.Message)
fldCol = Nothing
End Try
Return fldCol
End Function
The above code works perfectly when i have a recordset that has both
fields and values,
but gives the following error when i have an empty recordset
error: an exception of type:
{System.Runtime.InteropServices.COMException} occurred
when i want to create a new record, i need to create an empty
collection that has the fields so i can populate then from the form
and send back to the database via a command parameters.
eg mycol = loadcollection(rs.open ("select * from mytbl where id =
-1"))
pls advise what is wrong with the code and what can i do to remedy
this?
regards
Edwinah63
i have a collection containing the values and metadata about a current
record.
i build it by looping through the recordset as follows:
Public Function NoNull(ByVal Value As Object) As String
Return IIf(IsDBNull(Value), "", Value)
End Function
Public Function LoadFields(ByRef rs As ADODB.Recordset) As Collection
'returns fields of a single record
Dim fldCol As Collection
Dim p As PType
Dim i As Integer
fldCol = New Collection
Try
fldCol = New Collection
With rs
For i = 0 To .Fields.Count - 1
p = New PType
p.FieldName = .Fields(i).Name
p.Datatype = .Fields(i).Type
p.varValue = NoNull(.Fields(i).Value) '*** dies
here when no value
p.intLen = .Fields(i).DefinedSize()
fldCol.Add(p, p.FieldName)
Next i
End With
Catch e As Exception
Debug.WriteLine(e.Message)
fldCol = Nothing
End Try
Return fldCol
End Function
The above code works perfectly when i have a recordset that has both
fields and values,
but gives the following error when i have an empty recordset
error: an exception of type:
{System.Runtime.InteropServices.COMException} occurred
when i want to create a new record, i need to create an empty
collection that has the fields so i can populate then from the form
and send back to the database via a command parameters.
eg mycol = loadcollection(rs.open ("select * from mytbl where id =
-1"))
pls advise what is wrong with the code and what can i do to remedy
this?
regards
Edwinah63