search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

protected DataTable getData()

Asked by Dragan
11 years ago.

Can you help instead using this code to bind data from my sql database, and what to write in code, give some examples ?

DataTable dt;
dt = new DataTable();
dt.Columns.Add("start", typeof(DateTime));
dt.Columns.Add("end", typeof(DateTime));
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("id", typeof(string));
dt.Columns.Add("color", typeof (string));

DataRow dr;

dr = dt.NewRow();
dr["id"] = 0;
dr["start"] = Convert.ToDateTime("15:50");
dr["end"] = Convert.ToDateTime("15:55");
dr["name"] = "Event 1";
dt.Rows.Add(dr);
.
.
.

Answer posted by Dan Letecky [DayPilot]
11 years ago.

See a LINQ example here:
http://kb.daypilot.org/56894/how-to-use-daypilot-scheduler-with-linq-to-sql/

        var db = new DataClassesDataContext();
        var events = from ev in db.Events where !(ev.eventend <= start || ev.eventstart >= end) select ev;
        dps.DataSource = events;

Or a SqlDataAdapter example here:
http://code.daypilot.org/34377/shift-scheduling-tutorial-asp-net-sql-server-c-vb-net

public DataTable GetAssignmentsForLocation(DayPilotCalendar calendar)
{
  DataTable dt = new DataTable();

  // ...

  SqlDataAdapter da = new SqlDataAdapter("select * from [Assignment] join [Person] on [Assignment].[PersonId] = [Person].[PersonId] where NOT (([AssignmentEnd] <= @start) OR ([AssignmentStart] >= @end)) and [LocationId] = @location and [AssignmentRecurrence] is null", ConfigurationManager.ConnectionStrings["daypilot"].ConnectionString);
  da.SelectCommand.Parameters.AddWithValue("start", calendar.StartDate);
  da.SelectCommand.Parameters.AddWithValue("end", calendar.EndDate.AddDays(1));
  da.SelectCommand.Parameters.AddWithValue("location", (int) calendar.ClientState["location"]);
  da.Fill(dt);
  return dt;
}
This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.