This is a migrated thread and some comments may be shown as answers.

Insert to DataBase

1 Answer 116 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Farshad heidary
Top achievements
Rank 1
Farshad heidary asked on 10 Feb 2010, 11:51 AM
Hi guys.
here is my sqlcommand Code
<asp:SqlDataSource ID="SqlDataSource1" runat="server"  
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>"  
          
            SelectCommand="SELECT AppointmentID, Start, [End], Subject, Due, Priority, UserID FROM Appointments_DragAndDrop WHERE (Start IS NOT NULL) AND ([End] IS NOT NULL) AND (UserID = @UserID)" 
            InsertCommand="INSERT INTO Appointments_DragAndDrop(Subject, Start, [End], UserID) VALUES (@Subject, @Start, @End , @UserID)" 
            UpdateCommand="UPDATE [Appointments_DragAndDrop] SET [Start] = @Start, [End] = @End, [Subject] = @Subject WHERE AppointmentID = @AppointmentID" 
             
             
            DeleteCommand="DELETE FROM [Appointments_DragAndDrop] WHERE [AppointmentID] = @AppointmentID"
            <InsertParameters> 
                <asp:Parameter Name="Subject" Type="String" /> 
                <asp:Parameter Name="Start" Type="DateTime" /> 
                <asp:Parameter Name="End" Type="DateTime" /> 
                <asp:Parameter Name="UserID"   /> 
            </InsertParameters> 
            <UpdateParameters> 
                <asp:Parameter Name="Start" Type="DateTime" /> 
                <asp:Parameter Name="End" Type="DateTime" /> 
                <asp:Parameter Name="Subject" Type="String" /> 
                <asp:Parameter Name="AppointmentID" Type="Int32" /> 
            </UpdateParameters> 
            <SelectParameters> 
                <asp:SessionParameter DefaultValue="" Name="UserID" SessionField="UserID" /> 
            </SelectParameters> 
            <DeleteParameters> 
                <asp:Parameter Name="AppointmentID" Type="Int32" /> 
            </DeleteParameters> 
        </asp:SqlDataSource> 
And here is code behinde
 private void HandleSchedulerDrop(int id, string subject, string targetSlotIndex) 
    { 
        RadScheduler1.Rebind(); 
 
        ISchedulerTimeSlot slot = RadScheduler1.GetTimeSlotFromIndex(targetSlotIndex); 
 
        TimeSpan duration = TimeSpan.FromHours(1); 
        if (slot.Duration == TimeSpan.FromDays(1)) 
        { 
            duration = slot.Duration; 
        } 
        
        ScheduleAppointment(id, subject, slot.Start, slot.Start.Add(duration), Session["UserID"].ToString()); 
    } 
 
    private void ScheduleAppointment(int id, string subject, DateTime start, DateTime end,string UserID) 
    { 
        IDataSource dataSource = SqlDataSource1; 
        DataSourceView view = dataSource.GetView("DefaultView"); 
 
        IOrderedDictionary data = new OrderedDictionary(); 
        data.Add("Subject", subject); 
        data.Add("Start", start); 
        data.Add("End", end); 
        data.Add("UserID", UserID); 
 
        IDictionary keys = new OrderedDictionary(); 
        keys.Add("AppointmentID", id); 
      
        view.Update(keys, data, new OrderedDictionary(), OnDataSourceOperationComplete); 
        
    } 
 
    private static bool OnDataSourceOperationComplete(int count, Exception e) 
    { 
        if (e != null
        { 
            throw e; 
        } 
        return true
    } 
How ican Insert? Insert occure right and okey! but UserID field is null!?
how i can fill UserID column in database with Session?
(Update Select and Delete Is absolutely okey)
tnx guys

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 15 Feb 2010, 09:02 AM
Hi Farshad,

You should add another parameter to the ScheduleAppointment method to pass the resource. For example:

private void HandleSchedulerDrop(int id, string subject, string targetSlotIndex)
        {
            RadScheduler1.Rebind();
            ISchedulerTimeSlot slot = RadScheduler1.GetTimeSlotFromIndex(targetSlotIndex);
            TimeSpan duration = TimeSpan.FromHours(1);
            if (slot.Duration == TimeSpan.FromDays(1))
            {
                duration = slot.Duration;
            }
            ScheduleAppointment(id, subject, slot.Start, slot.Start.Add(duration), slot.Resource);
        }

private void ScheduleAppointment(int id, string subject, DateTime start, DateTime end, Resource res)
    {            
        Appointment appToInsert = new Appointment();
        appToInsert.Subject = subject;
        appToInsert.Start = start;
        appToInsert.End = end;
        appToInsert.Resources.Add(res);
        RadScheduler1.InsertAppointment(appToInsert);
    }


Greetings,
Peter
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Scheduler
Asked by
Farshad heidary
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or