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

insert from sqldatabase

4 Answers 44 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
omar
Top achievements
Rank 1
omar asked on 12 Jul 2011, 06:51 PM
Hi All

how are u 
I have problem when  i want to make insert value from database  MS SqlServer  plz
give me any code plz it's can save my appointment in DB i want code plz
thank u for all

4 Answers, 1 is accepted

Sort by
0
omar
Top achievements
Rank 1
answered on 13 Jul 2011, 10:33 AM
plz any info about this Question

0
Plamen
Telerik team
answered on 14 Jul 2011, 01:03 PM
Hi Omar,

The easiest way to achieve this is explained in our help topic  Declarative Data Binding and especially step 6 where it is explained how to autogenerate the Insert/Update /Delete statements.

Hope this will help you.

Greetings,
Plamen Zdravkov
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
omar
Top achievements
Rank 1
answered on 16 Jul 2011, 03:08 PM
Hi admin

 thank u for your reply  can not i understand  any think for  Explanation

what it's mean resource type
 i uswe this code for binding scheduler

Dim daadabterch As New SqlDataAdapter("select * from tbl_appointments", con)

Dim dssh As New DataSet

 

Try

 

 

con.Open()

daadabterch.Fill(dssh,

 

"tbl_appointments")

con.Close()

RadScheduler2.DataSource = (dssh)

RadScheduler2.DataMember =

 

 

 

 

 

"tbl_appointments"

RadScheduler2.DataKeyField =

 

 

 

 

 

"ID"

RadScheduler2.DataStartField =

 

 

 

 

 

"start"

RadScheduler2.DataEndField =

 

 

 

 

 

"end"

RadScheduler2.DataSubjectField =

 

 

 

 

 

"subject"

RadScheduler2.DataBind()

 

 

 

 

 

Catch ex As Exception

MsgBox(ex.ToString)

 

 

 

 

 

End Try

 

 

 

how can i user insert statment for insert data into DB SQL

thank u admin
0
Plamen
Telerik team
answered on 20 Jul 2011, 04:12 PM
Hello Omar,

You may also take a look at our Using The Data Source Property help topic.

If you need to update the appointments data source, you should handlethe AppointmentUpdate/Insert/Delete events. You can refer to the DataBase provider demo and see how the data source is manipulated on those events.  

publicoverridevoidInsert(RadScheduler owner, Appointment appointmentToInsert)  
     {         
  if(!PersistChanges)            {
                return;
           }
            using(DbConnection conn = OpenConnection())
            {
                using(DbTransaction tran = conn.BeginTransaction())
                {
                    DbCommand cmd = DbFactory.CreateCommand();
                    cmd.Connection = conn;
                    cmd.Transaction = tran;
                    PopulateAppointmentParameters(cmd, appointmentToInsert);
                   cmd.CommandText =
                        @"  INSERT  INTO [DbProvider_Classes]
 
                                    ([Subject], [Start], [End], [TeacherID],
  
                                    [RecurrenceRule], [RecurrenceParentID], [Reminder])
  
                            VALUES  (@Subject, @Start, @End, @TeacherID,
  
                                    @RecurrenceRule, @RecurrenceParentID, @Reminder)";
  
  
  
                    if(DbFactory isSqlClientFactory)
  
                    {
  
                        cmd.CommandText += Environment.NewLine + "SELECT SCOPE_IDENTITY()";
  
                    }
  
                    else
  
                    {
  
                        cmd.ExecuteNonQuery();
  
  
  
                        cmd.CommandText = "SELECT @@IDENTITY";
  
                    }
  
                    intidentity = Convert.ToInt32(cmd.ExecuteScalar());
  
  
  
                    FillClassStudents(appointmentToInsert, cmd, identity);
  
  
  
                    tran.Commit();
  
                }
  
            }
  
        }
  
  
  
        publicoverridevoidUpdate(RadScheduler owner, Appointment appointmentToUpdate)
  
        {
  
            if(!PersistChanges)
  
            {
  
                return;
  
            }
  
  
  
            using(DbConnection conn = OpenConnection())
  
            {
  
                using(DbTransaction tran = conn.BeginTransaction())
  
                {
  
                    DbCommand cmd = DbFactory.CreateCommand();
  
                    cmd.Connection = conn;
  
                    cmd.Transaction = tran;
  
  
  
                    PopulateAppointmentParameters(cmd, appointmentToUpdate);
  
  
  
                    cmd.Parameters.Add(CreateParameter("@ClassID", appointmentToUpdate.ID));
  
                    cmd.CommandText = "UPDATE [DbProvider_Classes] SET [Subject] = @Subject, [Start] = @Start, [End] = @End, [TeacherID] = @TeacherID, [RecurrenceRule] = @RecurrenceRule, [RecurrenceParentID] = @RecurrenceParentID WHERE [ClassID] = @ClassID";
  
                    cmd.ExecuteNonQuery();
  
  
  
                    ClearClassStudents(appointmentToUpdate.ID, cmd);
  
  
  
                    FillClassStudents(appointmentToUpdate, cmd, appointmentToUpdate.ID);
  
  
  
                    tran.Commit();
  
                }
  
            }
  
        }
  
  
  
        publicoverridevoidDelete(RadScheduler owner, Appointment appointmentToDelete)
  
        {
  
            if(!PersistChanges)
  
            {
  
                return;
  
            }
  
  
  
            using(DbConnection conn = OpenConnection())
  
            {
  
                DbCommand cmd = DbFactory.CreateCommand();
  
                cmd.Connection = conn;
  
  
  
                using(DbTransaction tran = conn.BeginTransaction())
  
                {
  
                    cmd.Transaction = tran;
  
  
  
                    ClearClassStudents(appointmentToDelete.ID, cmd);
  
  
  
                    cmd.Parameters.Clear();
  
                    cmd.Parameters.Add(CreateParameter("@ClassID", appointmentToDelete.ID));
  
                    cmd.CommandText = "DELETE FROM [DbProvider_Classes] WHERE [ClassID] = @ClassID";
  
                    cmd.ExecuteNonQuery();
  
  
  
                    tran.Commit();
  
                }
  
            }
  
        }

Greetings,

Plamen Zdravkov
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Scheduler
Asked by
omar
Top achievements
Rank 1
Answers by
omar
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or