Reputation: 101
I would like to read data from an SQL database, export it to XML and upload it to sharepoint. However, when using a SELECT statement via an IDbConnection to first read from the SQL database, I get unexpected returns. Can anyone explain why it returns 01/01/0001 00:00:00 and null for some columns?
[![date name check-in time of latest event latest event current status
public void SQL2SP()
{
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("")))
{
var presence = connection.Query<Presence>("SELECT * FROM ..."); # this is the statement that returns unexpected results
Events events = new Events();
var newData =
from element in presence
group element.Name by new { element.Date, element.Name, element.CheckIn, element.TimeOfLatestEvent, element.LatestEvent, element.Status }
into g
select new XElement("DATA",
new XAttribute("date", XmlConvert.ToString(g.Key.Date, "yyyy-MM-dd")),
new XAttribute("name", g.Key.Name),
new XAttribute("checkIn", XmlConvert.ToString(g.Key.CheckIn, "yyyy-MM-dd HH:mm:ss")),
new XAttribute("timeOfLatestEvent", XmlConvert.ToString(g.Key.TimeOfLatestEvent, "yyyy-MM-dd HH:mm:ss")),
new XAttribute("latestEvent", g.Key.LatestEvent),
new XAttribute("currentStatus", g.Key.Status));
public class Presence
{
public DateTime Date { get; set; }
public string Name { get; set; }
public DateTime CheckIn { get; set; }
public DateTime TimeOfLatestEvent { get; set; }
public string LatestEvent { get; set; }
public string Status { get; set; }
}
Upvotes: 0
Views: 573