Solved

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

Posted on 2010-11-16
12
685 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
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!

 

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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.Net remove carriage returns, line feeds and tabbs 5 36
Best book for Internet security 4 52
SSIS - Using VB.NET to parse XML file 11 40
Datatable / Dates ? 4 29
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

732 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