Solved

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

Posted on 2010-11-16
12
683 Views
Last Modified: 2012-05-10
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
 
0
Comment
Question by:rhill52
  • 6
  • 6
12 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 34151814
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.
0
 

Author Comment

by:rhill52
ID: 34153847
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)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 34155649
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?
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:rhill52
ID: 34156213
My dataset has an id field that is used as the autoid/primary key and the control has a readonly autoid.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 34156222
But, does the Appointment have a "primary key" property?
0
 

Author Comment

by:rhill52
ID: 34156271
Hi there is an autoid readonly and another id property see screen shot.
dataset.jpg
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 34156286
Cool!!  What version of VB.NET are you using?
0
 

Author Comment

by:rhill52
ID: 34156322
I Use Microsoft Visual Basic 2008 and the framework is 3.5

Thanks
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 34156434
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?
0
 

Author Comment

by:rhill52
ID: 34156449
Sorry am a beginner with VB so would need help.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 34161184
Aaah, beginning a new journey is my greatest joy in programming...there is a whole new world of possibilities ahead of you...

Start with a tutorial:

101 LINQ Samples
http://msdn.microsoft.com/en-us/vbasic/bb688088.aspx

With your learning, you might soon realize that LINQ syntax is a little similar to SQL queries against a database.

One tip, with DataTable, is that it is not directly queryable, without a little extra work.

LINQ query on a DataTable
http://stackoverflow.com/questions/10855/linq-query-on-a-datatable

You can't query against the DataTable's Rows collection, since DataRowCollection doesn't implement IEnumerable<T>. You need to use the AsEnumerable() extension for DataTable. Like so:

var results = from myRow in myDataTable.AsEnumerable()
where myRow.Field<int>("RowNo") == 1
select myRow;
And as Keith says, you'll need to add a reference to System.Data.DataSetExtensions

AsEnumerable() returns IEnumerable<DataRow>. If you need to convert IEnumerable<DataRow> to a DataTable, use the CopyToDataTable() extension.
0
 

Author Closing Comment

by:rhill52
ID: 34498014
Not really the route I wanted to take.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Multiple file Upload asp.net 2 49
VB 2005 Tooltips on Form Load Event 15 29
VB.Net - TypeInitializer Error 25 28
Error handling in asp.net site 5 28
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question