Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2094
ExtendedAppointmentInfo to/from Database
posted

I have created a small "ExtendedAppointmentInfo" class to store some additional appoinment info.

 <Serializable()> _
Public Class ExtendedAppointmentInfo
    Private _PhoneNumber As String = Nothing

    Public Property PhoneNumber() As String
        Get
            Return Me._PhoneNumber
        End Get
        Set(ByVal value As String)
            Me._PhoneNumber = value
        End Set
    End Property

End Class 

 

I have my CalendarInfo bound to a Dataset (manually created in code at the moment - will eventually move it to a database).  The AllPropertiesDataMember is a DataColumn called "AllProperties" and it has a data type of Byte()

 

Private Sub SaveAppointments(ByVal Appt as Appointment)

    Dim info As ExtendedAppointmentInfo = Nothing
    info = TryCast(Me.appointment.Tag, ExtendedAppointmentInfo)   

    info.PhoneNumber = "12345678"
    Appt.Tag = Info

    'Add Appointment to CalendarInfo
    Dim apptAsClone As ICloneable = DirectCast(Me.appointment, ICloneable)
    Me.calendarInfo.Appointments.Add(DirectCast(apptAsClone.Clone(), Appointment))

End Sub 

This All Works and Appointments.TAG property DOES appear to contain my "ExtendedAppointmentInfo" class. But I am having major problems trying to retrieve the data back.

 

For Instance. my data table was Declared "WITHEVENTS"

    Private Sub AppointmentsTable_RowChanged(ByVal sender As Object, ByVal e As System.Data.DataRowChangeEventArgs) Handles AppointmentsTable.RowChanged
        If e.Action = DataRowAction.Add Then
            If Not IsNothing(e.Row("AllProperties")) And e.Row("AllProperties") IsNot System.DBNull.Value Then
                Dim Appt As Appointment = Appointment.FromBytes(e.Row("AllProperties"))
                Dim ExtendedInfo As ExtendedAppointmentInfo = DirectCast(Appt.Tag, ExtendedAppointmentInfo)
                MessageBox.Show(ExtendedInfo.PhoneHome)
            End If
        End If
    End Sub
 

 The Problem is that When I try to retrieve the AllProperties column value it ALWAYS = System.DbNull.Value

 Please help. I need to be able to cast the "All Properties" column back into an appointment object, then cast the appointment.tag back into an ExtendedAppointmentInfo Class.

 

 

Parents
No Data
Reply
  • 2094
    Offline posted

    I should probably mention my ultimate goal which is:

     

    • SQL Database containing Both Owners Table and Appointments Table
    • Web Service in Between Database and Client (Doing actually read and writes from the databases)
    • The Appointments Table to Contain MORE than just the normal supported fields. For instance.
      • I want to store a PHONE number against the appointment record. This phone number must be "Query-able" from other webservices/functions/routines etc.
      • The Phone Number must be a column of its own in the appointments table - it is all well and nice to have it stored in the "All Properties" column stored as binary however I also need to Duplicate Some of the information in the serialized class stored in the Tag and subsequently stored in the "AllProperties" column as binary into thier own column.. ie; Phone Number

    I am having trouble getting the AllProperties Column to populate correctly... everytime i convert the Appointment using

    Dim Appt as Appointment = Appointment.FromBytes(_dataRoww("AllProperties"))

    When I try to access the .TAG info using:

    Dim MyClassInstance as MyClass = DirectCast(Appt.Tag,MyClass)

    It is ALWAYS Null :(

    At which point/which event should I capture the information in the Appt.Tag custom class and write it directly to my database? AfterAppointmentAdded? DataTable_RowChanged?

    I hope i have made a little more sense 

Children