Solved

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

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

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now