Link to home
Create AccountLog in
Avatar of rhill52
rhill52

asked on

How do I Write to my SQL dataset after an update to the Dotnetbar Schedule control ?

Hi I use the following code to read in a dataset and update the dotnet schedule control, I now need to do the reverse and write any changes to the dataset please help.

Private Sub ButtonItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItem2.Click
        'Me.ScheduleTableAdapter.Fill(Me.Inspections_Schedule_DataSet.Schedule)
        Me.ScheduleTableAdapter.Fill(Inspections_Schedule_DataSet.Schedule)
        For Each dr As DataRow In Inspections_Schedule_DataSet.Schedule.Rows

            Dim appointment As New Appointment()

            appointment.StartTime = dr("starttime")
            appointment.EndTime = dr("endtime")
            appointment.OwnerKey = dr("owner")
            appointment.Tag = dr("tag")
            appointment.Subject = dr("subject")
            appointment.Description = dr("description")
            appointment.CategoryColor = dr("categorycolor")
            appointment.Tooltip = appointment.Description

            Me.CalendarView1.CalendarModel.Appointments.Add(appointment)



        Next


        MessageBox.Show("data import finished!")
    End Sub

The control is availible for trial download from here  http://www.devcomponents.com/dotnetbar/download.aspx
 
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

I would suggest that if you kept the reference to the Appointment object, that you might be able to see the changes that the control makes to the object.  That would mean defining a module-level variable, instead of a local variable.
Avatar of rhill52
rhill52

ASKER

This works for writing to xml but I need to write to my SQL dataset and really only change the items that have been added

 Dim xml As New Xml.Writer(Application.StartupPath & "\Appointments.xml", "appointments")
        For Each appointment As Appointment In Form1.CalendarView1.CalendarModel.Appointments

            xml.WriteElement("appointment")
            xml.WriteAttribute("owner", appointment.OwnerKey)
            xml.WriteAttribute("start", appointment.StartTime)
            xml.WriteAttribute("end", appointment.EndTime)
            xml.WriteAttribute("preremind", Convert.ToInt32(appointment.Tag))
            xml.WriteAttribute("subject", appointment.Subject)
            xml.WriteAttribute("description", appointment.Description)
            xml.WriteAttribute("color", appointment.CategoryColor)
            xml.WriteAttribute("timemarker", appointment.TimeMarkedAs)
In order to work with the appointments that are added, then you would need to have a way to uniquely identify an Appointment object (a primary key, if you will).  Does the Appointment object have something like a Key property.  Does your table have a primary key?
Avatar of rhill52

ASKER

My dataset has an id field that is used as the autoid/primary key and the control has a readonly autoid.
But, does the Appointment have a "primary key" property?
Avatar of rhill52

ASKER

Hi there is an autoid readonly and another id property see screen shot.
dataset.jpg
Cool!!  What version of VB.NET are you using?
Avatar of rhill52

ASKER

I Use Microsoft Visual Basic 2008 and the framework is 3.5

Thanks
If you have 3.5 or greater, than you could use a LINQ query to get a list of Appointment objects that are new (Left Outer Join).  The Appointment ID appears to be the same primary key that is used in the DataTable.

How much do you know about LINQ?
Avatar of rhill52

ASKER

Sorry am a beginner with VB so would need help.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of rhill52

ASKER

Not really the route I wanted to take.