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

protected DataTable getData()

Asked by Dragan
9 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";

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

See a LINQ example here:

        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:

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"]);
  return dt;
This question is more than 3 months old and has been closed. Please create a new question if you have anything to add.