?
Solved

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

Posted on 2010-11-16
12
Medium Priority
?
700 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 1500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

777 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