我有两张桌子:
事件:
-ID; 姓名; 开始事件;结束事件;个人ID;
RegistracijaKorisnik:
-ID; 我;
现在我写了这个:
SqlDataAdapter da = new SqlDataAdapter(
"SELECT [id], [name], [eventstart], [eventend] " +
"FROM [Event] " +
"WHERE NOT (([eventend] <= @start) OR ([eventstart] >= @end))",
con);
有了这个唯一的显示名称,eventstart,eventend。现在我想显示来自 Person 表的名称和来自 event 的 name、eventstart、eventend。在 Event 表中,我想将 Event 表中的 PersonID 连接到 Person 表中的 ID 字段。你能帮助我吗?
编辑:所有代码,不知道为什么不显示 p.ime
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DayPilotCalendar1.StartDate = DayPilot.Utils.Week.FirstDayOfWeek(new DateTime(2012, 09, 17));
DayPilotCalendar1.DataSource = dbGetEvents(DayPilotCalendar1.StartDate, DayPilotCalendar1.Days);
DataBind();
}
}
protected DataTable dbGetEvents(DateTime start, int days)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=Korisnik;Integrated Security=True";
//SqlDataAdapter da = new SqlDataAdapter("SELECT [id], [name], [eventstart], [eventend] FROM [Event] WHERE NOT (([eventend] <= @start) OR ([eventstart] >= @end))", con);
//SqlDataAdapter da = new SqlDataAdapter("select e.id as EventId, e.name as EventName, e.eventstart, e.eventend, p.Id as PersonId, p.ime as PersonName from Event e inner join RegistracijaKorisnik p on e.PersonID=p.id where not (([eventend] <= @start) OR ([eventstart] >= @end))", con);
//SqlDataAdapter da = new SqlDataAdapter("SELECT e.id, e.name, e.eventstart, e.eventend, p.ime FROM Event e INNER JOIN RegistracijaKorisnik p ON e.PersonID = p.id WHERE NOT ((e.eventend <= @start) OR (e.eventstart >= @end ))", con);
SqlDataAdapter da = new SqlDataAdapter("SELECT e.id, e.name, e.eventstart, e.eventend, p.ime AS 'Person Name' FROM Event e INNER JOIN RegistracijaKorisnik p ON e.PersonID = p.id WHERE NOT ((e.eventend <= @start) OR (e.eventstart >= @end ))", con);
da.SelectCommand.Parameters.AddWithValue("start", start);
da.SelectCommand.Parameters.AddWithValue("end", start.AddDays(days));
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}