我正在處理大量的約會,以便csv向用戶發送通知等。我想要做的就是設置一個isProcessed
標誌來表示當前行已經被處理了我不知道該怎麼辦在我目前的循環中。批量導出爲CSV
public void DumpTableToFile(SqlConnection connection, string tableName, string destinationFile)
{
using (var command = new SqlCommand("select LineType,CustomerFirstName AS 'Forename' ,CustomerLastName,Age,dob as 'Date of Birth',maritalStatus AS 'Marital Status',homePhone AS 'Home', mobileNumber AS Mobile,emailAddress AS Email,Address1 + Address2 + PostCode AS 'Address' ,employmentStatus AS Employment,occupation AS Occupation,propertyValue AS 'Property Value',mortgageBalance AS 'Mortgage Balance',balanceOnSecuredDebt AS 'Balance on secured Debt',mortgageType as 'Mortgage Type' from " + tableName, connection))
using (var reader = command.ExecuteReader())
using (var outFile = File.CreateText(destinationFile))
{
string[] columnNames = GetColumnNames(reader).ToArray();
int numFields = columnNames.Length;
outFile.WriteLine(string.Join(",", columnNames));
if (reader.HasRows)
{
while (reader.Read())
{
string[] columnValues =
Enumerable.Range(0, numFields)
.Select(i => reader.GetValue(i).ToString())
.Select(field => string.Concat("\"", field.Replace("\"", "\"\""), "\""))
.ToArray();
outFile.WriteLine(string.Join(",", columnValues));
}
}
}
的標誌被稱爲isProcessed,我想將它設置爲true
一旦其通過CSV導出了。這是我可以做批量出口。它存在於同一個表約會
編輯在1
對不起,不說明,我想這個標誌被寫回預約表,它是在CSV吐出導出CSV了短路電流記錄出口工程我只需要一種方法來確定它已被導出,所以它不再被處理。
你要什麼這個標誌呢?它應該是你寫出的文件的一部分嗎?內存中狀態? –
@EricJ。在那裏做了一個編輯來解釋我自己,請參閱編輯1 – rogue39nin
非常感謝您的投票uppreferred, – rogue39nin