本文整理汇总了C#中CsvReader.ReadNextRecord方法的典型用法代码示例。如果您正苦于以下问题:C# CsvReader.ReadNextRecord方法的具体用法?C# CsvReader.ReadNextRecord怎么用?C# CsvReader.ReadNextRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CsvReader
的用法示例。
在下文中一共展示了CsvReader.ReadNextRecord方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LastFieldEmptyFollowedByMissingFieldsOnNextRecord
public void LastFieldEmptyFollowedByMissingFieldsOnNextRecord()
{
const string Data = "a,b,c,d,e"
+ "\na,b,c,d,"
+ "\na,b,";
using (var csv = new CsvReader(new StringReader(Data), false))
{
csv.MissingFieldAction = MissingFieldAction.ReplaceByNull;
var record = new string[5];
Assert.IsTrue(csv.ReadNextRecord());
csv.CopyCurrentRecordTo(record);
Assert.AreEqual(new string[] { "a", "b", "c", "d", "e" }, record);
Assert.IsTrue(csv.ReadNextRecord());
csv.CopyCurrentRecordTo(record);
Assert.AreEqual(new string[] { "a", "b", "c", "d", "" }, record);
Assert.IsTrue(csv.ReadNextRecord());
csv.CopyCurrentRecordTo(record);
Assert.AreEqual(new string[] { "a", "b", "", null, null }, record);
Assert.IsFalse(csv.ReadNextRecord());
}
}
示例2: BatchProcessStewardshipTechnology
public static int? BatchProcessStewardshipTechnology(CsvReader csv, DateTime date, int? fundid)
{
var fundList = (from f in DbUtil.Db.ContributionFunds
select new
{
f.FundId,
f.FundName
}).ToList();
var cols = csv.GetFieldHeaders();
BundleHeader bh = null;
var firstfund = FirstFundId();
var list = new List<depositRecord>();
csv.ReadNextRecord();
while (csv.ReadNextRecord())
list.Add(new depositRecord()
{
date = csv[1].ToDate(),
account = csv[6],
amount = csv[2],
checkno = csv[0],
type = csv[3],
});
DateTime? prevbatch = null;
foreach(var r in list.OrderBy(rr => rr.date))
{
if (r.date != prevbatch)
{
if (bh != null)
FinishBundle(bh);
bh = GetBundleHeader(r.date ?? date, DateTime.Now, BundleTypeCode.Online);
bh.DepositDate = r.date;
prevbatch = r.date;
}
BundleDetail bd;
var fid = (from f in fundList
where f.FundName == r.type
select f.FundId).SingleOrDefault();
if(fid > 0)
bd = AddContributionDetail(r.date ?? date, fid, r.amount, r.checkno, "", r.account);
else
{
bd = AddContributionDetail(r.date ?? date, fundid ?? firstfund, r.amount, r.checkno, "", r.account);
bd.Contribution.ContributionDesc = "Used default fund (fund requested: {0})".Fmt(r.type);
}
bh.BundleDetails.Add(bd);
}
FinishBundle(bh);
return bh.BundleHeaderId;
}
示例3: ImportDescriptionData
void ImportDescriptionData(TextAsset csv,List<DescriptionData> descriptions)
{
if(csv == null) return;
CsvReader parser = new CsvReader(new StringReader(csv.text),true);
descriptions.Clear();
while (parser.ReadNextRecord())
{
DescriptionData data = new DescriptionData();
data.type = parser[0];
float probability = 0.0f;
float.TryParse(parser[1], out probability);
data.probability = probability;
data.text = parser[2];
int group = 0;
int.TryParse(parser[3], out group);
data.group = group;
int mimic = 0;
int.TryParse(parser[4], out mimic);
data.mimic = (mimic == 1);
data.theme = (parser[5] == null ? "" : parser[5]);
descriptions.Add(data);
}
}
示例4: Import
private static int? Import(CsvReader csv, DateTime date, int? fundid)
{
BundleHeader bundleHeader = null;
var fid = fundid ?? BatchImportContributions.FirstFundId();
var details = new List<BundleDetail>();
while (csv.ReadNextRecord())
{
var batchDate = csv[0].ToDate();
var amount = csv[14];
var type = csv[13];
if (!amount.HasValue() || !batchDate.HasValue || type == "Credit")
continue;
var routingNumber = csv[17];
var accountNumber = csv[16];
var checkNumber = csv[15];
if (bundleHeader == null)
bundleHeader = BatchImportContributions.GetBundleHeader(batchDate.Value, DateTime.Now);
details.Add(BatchImportContributions.AddContributionDetail(date, fid, amount, checkNumber, routingNumber, accountNumber));
}
details.Reverse();
foreach (var bd in details)
{
bundleHeader.BundleDetails.Add(bd);
}
BatchImportContributions.FinishBundle(bundleHeader);
return bundleHeader.BundleHeaderId;
}
示例5: BatchProcessAbundantLife
private static int? BatchProcessAbundantLife(CsvReader csv, DateTime date, int? fundid)
{
BundleHeader bh = null;
var fid = fundid ?? BatchImportContributions.FirstFundId();
var prevbatch = "";
while (csv.ReadNextRecord())
{
var batch = csv[5];
if (bh == null || batch != prevbatch)
{
if (bh != null)
BatchImportContributions.FinishBundle(bh);
bh = BatchImportContributions.GetBundleHeader(date, DateTime.Now);
prevbatch = batch;
continue; // the first row of a batch is a total row
}
var amount = csv[3];
var routing = csv[8];
var account = csv[9];
var checkno = csv[10];
var bd = BatchImportContributions.AddContributionDetail(date, fid, amount, checkno, routing, account);
bh.BundleDetails.Add(bd);
}
BatchImportContributions.FinishBundle(bh);
return bh?.BundleHeaderId;
}
示例6: deleteTypeToolStripButton_Click
private void deleteTypeToolStripButton_Click(object sender, EventArgs e)
{
bool a = false;
if (selectIndex != -1)
{
using (CsvReader csv = new CsvReader(new StreamReader("Car.csv"), true, ';'))
{
while (csv.ReadNextRecord())
{
if (selectId.ToString() == csv[IdColumn.id_TypeId])
{
MessageBox.Show("Неможливо видалити, даний тип кузова використовується!");
a = true;
break;
}
}
}
if (!a)
{
DialogResult resut = MessageBox.Show("Тип кузова " + dataGridViewType.Rows[selectIndex].Cells[2].Value + " не використовується.\nВидалити?", "Увага!", MessageBoxButtons.YesNo);
if (resut == DialogResult.Yes)
{
color.Remove(selectId);
dataGridViewType.Rows.RemoveAt(selectIndex);
}
}
}
}
示例7: BatchProcessFbcFayetteville
private static int? BatchProcessFbcFayetteville(CsvReader csv, DateTime date, int? fundid)
{
var cols = csv.GetFieldHeaders();
BundleHeader bh = null;
var firstfund = FirstFundId();
var fund = fundid ?? firstfund;
while (csv.ReadNextRecord())
{
if (csv[6].StartsWith("Total Checks"))
continue;
var routing = csv[4];
var account = csv[5];
var checkno = csv[6];
var amount = csv[7];
if (bh == null)
bh = GetBundleHeader(date, DateTime.Now);
var bd = AddContributionDetail(date, fund, amount, checkno, routing, account);
bh.BundleDetails.Add(bd);
}
if (bh == null)
return null;
FinishBundle(bh);
return bh.BundleHeaderId;
}
示例8: parseHolidayhomes
//Create List to store your CSV data
public List<Models.Holidayhome> parseHolidayhomes()
{
CsvReader csv = new CsvReader(reader, true);
int fieldCount = csv.FieldCount;
List<Holidayhome> holidaylist = new List<Holidayhome>();
String[] headers = csv.GetFieldHeaders();
while (csv.ReadNextRecord())
{
Holidayhome exObj = new Holidayhome();
for (int i = 0; i < fieldCount; i++)
{
if (headers[i].Equals("holidayhomeno")) {exObj.holidayhomeno = csv[i];}
else if (headers[i].Equals("address1")) { exObj.address1 = csv[i]; }
else if (headers[i].Equals("address2")) { exObj.address2 = csv[i]; }
else if (headers[i].Equals("country")) { exObj.country = csv[i]; }
else if (headers[i].Equals("email")) { exObj.email = csv[i]; }
else if (headers[i].Equals("contactno")){ exObj.contactno = csv[i];}
else if (headers[i].Equals("amenities")){ exObj.amenities = csv[i];}
else if (headers[i].Equals("price")) { exObj.price = csv[i]; }
}
holidaylist.Add(exObj);
}
return holidaylist;
}
示例9: parseMuseums
public List<Models.Museum> parseMuseums()
{
CsvReader csv = new CsvReader(reader, true);
int fieldCount = csv.FieldCount;
List<Museum> exList = new List<Museum>();
Museum exObj = null;
String[] headers = csv.GetFieldHeaders();
while (csv.ReadNextRecord())
{
string cityStr = null;
double lat = 0, lng = 0;
string theName = null, theUrl = null, add1 = null, add2 = null, theZip = null, phone = null;
for (int i = 0; i < fieldCount; i++)
{
// this is where you actually create your dB object
if (headers[i].Equals("Shape"))
{
parseShape(csv[i], ref lat, ref lng);
}
else if (headers[i].Equals("NAME"))
{
theName = csv[i];
}
else if (headers[i].Equals("TEL"))
{
phone = csv[i];
}
else if (headers[i].Equals("URL"))
{
theUrl = csv[i];
}
else if (headers[i].Equals("ADRESS1")) // intentionally misspelt
{
add1 = csv[i];
}
else if (headers[i].Equals("ADDRESS2"))
{
add2 = csv[i];
}
else if (headers[i].Equals("ZIP"))
{
theZip = csv[i];
}
else if (headers[i].Equals("CITY"))
{
cityStr = csv[i];
}
}
exObj = new Museum(lat, lng, theName, phone, theUrl, add1, add2, theZip, cityStr);
exList.Add(exObj);
}
return exList;
//throw new NotImplementedException();
}
示例10: Main
static void Main(string[] args)
{
List<int[]> trainingData = new List<int[]>();
List<int> labels = new List<int>();
using (CsvReader csv =
new CsvReader(new StringReader(Properties.Resources.kaggle_train), true))
{
int fieldCount = csv.FieldCount;
Console.WriteLine("Field count: {0}", fieldCount);
string[] headers = csv.GetFieldHeaders();
while(csv.ReadNextRecord())
{
List<int> trainingExample = new List<int>();
labels.Add(int.Parse(csv[0]));
for(int i = 1; i < fieldCount; i++)
{
trainingExample.Add(int.Parse(csv[i]));
}
trainingData.Add(trainingExample.ToArray());
}
}
Console.WriteLine("Total examples: {0}", trainingData.Count);
Console.WriteLine("Total labels: {0}", labels.Count);
}
示例11: parseBookings
//Create List to store your CSV data
public List<Models.Booking> parseBookings()
{
CsvReader csv = new CsvReader(reader, true);
int fieldCount = csv.FieldCount;
List<Booking> bookinglist = new List<Booking>();
String[] headers = csv.GetFieldHeaders();
while (csv.ReadNextRecord())
{
Booking exObj = new Booking();
for (int i = 0; i < fieldCount; i++)
{
if (headers[i].Equals("holidayhomeno")) { exObj.holidayhomeno = csv[i]; }
else if (headers[i].Equals("customername")) { exObj.customername = csv[i]; }
else if (headers[i].Equals("address")) { exObj.address = csv[i]; }
else if (headers[i].Equals("price")) { exObj.price = csv[i]; }
else if (headers[i].Equals("startdate")) { exObj.startdate = csv[i]; }
else if (headers[i].Equals("enddate")) { exObj.enddate = csv[i]; }
else if (headers[i].Equals("creditcardtype")) { exObj.creditcardtype = csv[i]; }
else if (headers[i].Equals("expirydate")) { exObj.expirydate = csv[i]; }
}
bookinglist.Add(exObj);
}
return bookinglist;
}
示例12: BatchProcessVanco2
private static int? BatchProcessVanco2(CsvReader csv, DateTime date, int? fundid)
{
var fundList = (from f in DbUtil.Db.ContributionFunds
orderby f.FundId
select f.FundId).ToList();
var cols = csv.GetFieldHeaders();
BundleHeader bh = null;
var firstfund = BatchImportContributions.FirstFundId();
var fund = fundid != null && fundList.Contains(fundid ?? 0) ? fundid ?? 0 : firstfund;
while (csv.ReadNextRecord())
{
var routing = "0";
var checkno = "0";
var account = csv[0];
var amount = csv[7];
var fundText = csv[11];
if (bh == null)
bh = BatchImportContributions.GetBundleHeader(date, DateTime.Now);
var f = DbUtil.Db.FetchOrCreateFund(fundText);
var bd = BatchImportContributions.AddContributionDetail(date, f.FundId, amount, checkno, routing, account);
bh.BundleDetails.Add(bd);
}
BatchImportContributions.FinishBundle(bh);
return bh.BundleHeaderId;
}
示例13: BatchProcessEnon
private static int? BatchProcessEnon(CsvReader csv, DateTime date, int? fundid)
{
var cols = csv.GetFieldHeaders();
BundleHeader bh = null;
var fid = fundid ?? BatchImportContributions.FirstFundId();
while (csv.ReadNextRecord())
{
var dt = csv[2].ToDate();
var amount = csv[7];
if (!amount.HasValue() || !dt.HasValue)
continue;
var account = csv[5];
var checkno = csv[6];
if (bh == null)
bh = BatchImportContributions.GetBundleHeader(dt.Value, DateTime.Now);
var bd = BatchImportContributions.AddContributionDetail(date, fid, amount, checkno, "", account);
bh.BundleDetails.Add(bd);
}
BatchImportContributions.FinishBundle(bh);
return bh.BundleHeaderId;
}
示例14: UploadButton_Click
protected void UploadButton_Click(object sender, EventArgs e)
{
if (FileUploader.HasFile)
{
try
{
using (CsvReader csv = new CsvReader(new StreamReader(FileUploader.FileContent), true))
{
int count = 0;
while (csv.ReadNextRecord())
{
DepartmentPersonTableAdapters.un_ref_co_dept_peopleTableAdapter personTA = new DepartmentPersonTableAdapters.un_ref_co_dept_peopleTableAdapter();
personTA.Insert((int)Session[WebConstants.Session.REG_DEPT_ID], (int)Session[WebConstants.Session.REG_CO_ID],csv[0],
(int)Session[WebConstants.Session.REG_USER_ID], ParseBoolean(csv[1]), ParseBoolean(csv[2]), ParseBoolean(csv[3]));
count++;
}
SetInfoMessage(count + " people added to the system.");
}
}
catch(Exception ex)
{
SetErrorMessage("Error processing the file. Please check its contents. File should be CSV and in the format shown below");
}
}
else
{
SetErrorMessage("No file specified");
}
}
示例15: MissingFieldQuotedTest2
public void MissingFieldQuotedTest2()
{
const string Data = "a,b,c,d\n" +
"1,1,1,1\n" +
"2,\"2\",\n" +
"3,3,3,3";
try
{
using (CsvReader csv = new CsvReader(new StringReader(Data), false, 11))
{
while (csv.ReadNextRecord())
for (int i = 0; i < csv.FieldCount; i++)
{
string s = csv[i];
}
}
}
catch (MissingFieldCsvException ex)
{
if (ex.LineNumber == 3 && ex.FieldNumber == 3 && ex.ColumnNumber == 6)
throw ex;
Assert.Fail(string.Format("expected failure at Line number 2 (was {0}), field 3 (was {1}), column 6 (was {2})", ex.LineNumber, ex.FieldNumber, ex.ColumnNumber));
}
}