我使用這個庫:的DataReader的SqlBulkCopy的
把從XML一些LINQ查詢結果解析到一個數據庫與我們上課一個DataReader把數據使用SqlBulkCopy直接不使用數據表或這種數據結構。
我無法執行它。
這是我至今寫了沒有任何成功的代碼:
XDocument xdoc = XDocument.Parse(str_XmlToParse);
//ORDINI
IEnumerable<XDocument> xdod;
var orders = from c in xdoc.Descendants("ordersdata").AsEnumerable().Descendants("order").AsEnumerable()
select new
{
Client_ID = (string)c.Element("Client").Element("ID"),
Doc_ID = (string)c.Element("ord_ID"),
Doc_data = (DateTime)c.Element("ord_datetime"),
};
IDataReader dr = orders.AsDataReader();
using (SqlConnection con = new SqlConnection(connectionString))
{
con.Open();
using (SqlTransaction tran = con.BeginTransaction())
{
var newOrders =
from i in Enumerable.Range(0, totalToSend)
select new Order
{
customer_name = "Customer " + i % 100,
quantity = i % 9,
order_id = i,
order_entry_date = DateTime.Now
};
SqlBulkCopy bc = new SqlBulkCopy(con,
SqlBulkCopyOptions.CheckConstraints |
SqlBulkCopyOptions.FireTriggers |
SqlBulkCopyOptions.KeepNulls, tran);
bc.BatchSize = 1000;
bc.DestinationTableName = "order_queue";
bc.WriteToServer(newOrders.AsDataReader());
tran.Commit();
}
con.Close();
其中大部分是對什麼是在該庫的實例副本。
我甚至沒有正確理解他們所有奇怪的鑄件會發生什麼,但我需要它的工作。 (相信我,我試圖理解)
我不斷收到此錯誤:
Error 1 'System.Collections.Generic.IEnumerable AnonymousType#1>' does not contain a definition for 'AsDataReader' and no extension method 'AsDataReader' accepting a first argument of type 'System.Collections.Generic.IEnumerable AnonymousType#1>' could be found (are you missing a using directive or an assembly reference?)
這是什麼?我如何解決它?
感謝
PS。我認爲這是一個編譯器錯誤,而不是一個例外。正確? – Aron
你好。我非常渴望得到這個圖書館。我跟着鏈接,但它已經退休了。任何人都知道我可以在哪裏下載它? – serlingpa
@serlingpa 也許爲時已晚,但.... https://code.msdn.microsoft.com/windowsdesktop/WPF-783fc64b/sourcecode?fileId=94546&pathId=1773531594 –