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.F ill(Me.Ins pections_S chedule_Da taSet.Sche dule)
Me.ScheduleTableAdapter.Fi ll(Inspect ions_Sched ule_DataSe t.Schedule )
For Each dr As DataRow In Inspections_Schedule_DataS et.Schedul e.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.CalendarM odel.Appoi ntments.Ad d(appointm ent)
Next
MessageBox.Show("data import finished!")
End Sub
The control is availible for trial download from here http://www.devcomponents.com/dotnetbar/download.aspx
Private Sub ButtonItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItem2.Click
'Me.ScheduleTableAdapter.F
Me.ScheduleTableAdapter.Fi
For Each dr As DataRow In Inspections_Schedule_DataS
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.CalendarM
Next
MessageBox.Show("data import finished!")
End Sub
The control is availible for trial download from here http://www.devcomponents.com/dotnetbar/download.aspx
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.
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.Sta rtupPath & "\Appointments.xml", "appointments")
For Each appointment As Appointment In Form1.CalendarView1.Calend arModel.Ap pointments
xml.WriteElement("appointm ent")
xml.WriteAttribute("owner" , appointment.OwnerKey)
xml.WriteAttribute("start" , appointment.StartTime)
xml.WriteAttribute("end", appointment.EndTime)
xml.WriteAttribute("prerem ind", Convert.ToInt32(appointmen t.Tag))
xml.WriteAttribute("subjec t", appointment.Subject)
xml.WriteAttribute("descri ption", appointment.Description)
xml.WriteAttribute("color" , appointment.CategoryColor)
xml.WriteAttribute("timema rker", appointment.TimeMarkedAs)
Dim xml As New Xml.Writer(Application.Sta
For Each appointment As Appointment In Form1.CalendarView1.Calend
xml.WriteElement("appointm
xml.WriteAttribute("owner"
xml.WriteAttribute("start"
xml.WriteAttribute("end", appointment.EndTime)
xml.WriteAttribute("prerem
xml.WriteAttribute("subjec
xml.WriteAttribute("descri
xml.WriteAttribute("color"
xml.WriteAttribute("timema
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?
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?
ASKER
Hi there is an autoid readonly and another id property see screen shot.
dataset.jpg
dataset.jpg
Cool!! What version of VB.NET are you using?
ASKER
I Use Microsoft Visual Basic 2008 and the framework is 3.5
Thanks
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?
How much do you know about LINQ?
ASKER
Sorry am a beginner with VB so would need help.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Not really the route I wanted to take.