Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Thu, 14 Oct 2010 @ 19:11:22 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: Provider does not support conversion from VarChar to System.Boolean
 
From:   Aldrin, John

Here is what I have been using in .NET3.5 for a couple of years. I just finished testing it on .NET4.0 last week.

This works by using a CHAR(1) column in Teradata that contains the letter "Y" or "N". The logic defaults a NULL value to False.

    Public Function DBGetBool(ByRef dataField As Object) As Boolean
        If (IsDBNull(dataField) = True) Then
            Return False
        ElseIf CChar(dataField) = "N" Then
            Return False
        ElseIf (dataField Is Nothing) Then
            Return False
        Else
            Return True
        End If
    End Function

SAMPLE:

     ' ----- Load in the existing item.
     sqlText = "SELECT * FROM ItemCopy WHERE ID = " & ActiveCopy
     dbInfo = CreateReader(sqlText)
     dbInfo.Read()
     RecordAvailable.Checked = DBGetBool(dbInfo!Available)
     RecordReference.Checked = DBGetBool(dbInfo!Reference)
     RecordMissing.Checked = DBGetBool(dbInfo!Missing)


     Public Function DBBool(ByVal BoolVal As Boolean) As String
         If BoolVal Then
             Return "'Y'"
         Else
             Return "'N'"
         End If
     End Function

SAMPLE:

     sqlText = "INSERT INTO ItemCopy (ItemID, CopyNumber, Description, " & _
         "Barcode, Available, Reference, Missing, Acquired, Cost, Status, " & _
         "Condition, Location) VALUES (" & ActiveItem & _
         ", " & RecordCopy.Text & _
         ", " & DBText(Trim(RecordDescription.Text)) & _
         ", " & DBText(Trim(RecordBarcode.Text)) & _
         ", " & DBBool(RecordAvailable.Checked) & _
         ", " & DBBool(RecordReference.Checked) & _
         ", " & DBBool(RecordMissing.Checked) & _
         ", " & DBDate(RecordAcquired.Text) & _
         ", " & DBNum(RecordCost.Text) & _
         ", " & DBCombo(RecordGeneralStatus) & _
         ", " & DBText(Trim(RecordCondition.Text)) & _
         ", " & DBCombo(RecordLocation) & ")"
     newID = ExecuteSQLIdentity(sqlText)


     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023