0
是否可以導出以插入查詢?將數據從文件複製到數據存儲
我有一個疑問,在頁面(http://www.filehelpers.net/)中的圖像「高級用途的庫:將數據從文件複製到數據存儲」但我找不到信息,並知道我是否可以導出到SQL。
是否可以導出以插入查詢?將數據從文件複製到數據存儲
我有一個疑問,在頁面(http://www.filehelpers.net/)中的圖像「高級用途的庫:將數據從文件複製到數據存儲」但我找不到信息,並知道我是否可以導出到SQL。
這應該工作:
[DelimitedRecord("|")]
public class CustomersVerticalBar
{
public string CustomerID;
public string CompanyName;
public string ContactName;
public string ContactTitle;
public string Address;
public string City;
public string Country;
}
class Program
{
private static string GetInsertSqlCust(object record)
{
CustomersVerticalBar obj = (CustomersVerticalBar)record;
return String.Format("INSERT INTO Customers (Address, City, CompanyName, ContactName, ContactTitle, Country, CustomerID) " +
" VALUES ('{0}' , '{1}' , '{2}' , '{3}' , '{4}' , '{5}' , '{6}' ); ",
obj.Address,
obj.City,
obj.CompanyName,
obj.ContactName,
obj.ContactTitle,
obj.Country,
obj.CustomerID
);
}
static void Main(string[] args)
{
SqlServerStorage storage = new SqlServerStorage(typeof(CustomersVerticalBar));
storage.ServerName = "MYSERVER";
storage.DatabaseName = "Northwind";
// Comment this for Windows Auth
storage.UserName = "shamp00";
storage.UserPass = "whatever";
storage.InsertSqlCallback = new InsertSqlHandler(GetInsertSqlCust);
storage.InsertRecords(CommonEngine.ReadFile(typeof(CustomersVerticalBar), "infile.txt"));
Console.ReadKey();
}
}
我敢肯定,曾經有一些這方面的文檔 - 他們似乎從最新的網站缺少的。您可以查看FileHelpers源代碼中的單元測試some more examples。
向我們展示您的嘗試。您沒有放入任何代碼,並且添加了到第三方網站的鏈接 –