我有一个Datatable和DataRows,那些DataRows从XML文件获取值。
DataRow row = table.NewRow();
row["InvoiceNumber"] = xmlData.ChildNodes[2].ChildNodes[0].ChildNodes[2].ChildNodes[0].InnerText;
row["InvoiceIssueDate"] = Convert.ToDateTime(xmlData.ChildNodes[2].ChildNodes[0].ChildNodes[2].ChildNodes[1].InnerText);
row["InvoiceDeliveryDate"] = Convert.ToDateTime(xmlData.ChildNodes[2].ChildNodes[0].ChildNodes[2].ChildNodes[2].InnerText);
但是当我要将这些行添加到Entity Framework表中时,就会出现错误。
Invoices invoices = new Invoices();
invoices.InvoiceNumber = table.Rows[0].ToString();
invoices.InvoiceIssueDate = table.Rows[1];
invoices.InvoiceDeliveryDate = table.Rows[2];
我应该如何转换它们?
答案 0 :(得分:1)
尝试一下。
invoices.InvoiceIssueDate = Convert.ToDateTime(table.Rows[1]);
invoices.InvoiceDeliveryDate = Convert.ToDateTime(table.Rows[2]);