gpt4 book ai didi

c# - .NET CSV uploader 允许空值

转载 作者:行者123 更新时间:2023-12-04 01:59:29 26 4
gpt4 key购买 nike

我已经组合了一个我认为可以工作的 CSV 导入器,虽然我收到了这个错误,但我如何允许该列为空,以便将它添加到表中时它会自动设置 ID?我试过了:

csv.Configuration.WillThrowOnMissingFields = false;

但它无法识别,这是我尝试上传时遇到的错误:

CsvHelper.ValidationException: 'Header matching ['ID'] names at index 0 was not found. If you are expecting some headers to be missing and want to ignore this validation, set the configuration HeaderValidated to null. You can also change the functionality to do something else, like logging the issue.'


    [HttpPost]
[ActionName("CreateBulk")]
public ActionResult CreateBulkUpload()
{
object db;
var file = Request.Files["attachmentcsv"];
using (var csv = new CsvReader(new StreamReader(file.InputStream), true))
{
var records = csv.GetRecords<Client>().ToList();
foreach (var item in records)
{
var strip = item.homePage.Replace("https://www.", "").Replace("http://www.", "")
.Replace("https://", "").Replace("http://", "").Replace("www.", "");

string[] URLtests =
{"https://www." + strip, "http://www." + strip, "https://" + strip, "http://" + strip};

string[] Metric = MajesticFunctions.MajesticChecker(URLtests);
var userId = User.Identity.GetHashCode();
var UserTableID = 1;

var newclient = new Client

{
clientN = item.clientN,
homePage = Metric[0],
clientEmail = item.clientEmail,
monthlyQuota = item.monthlyQuota,
TrustFlow = Int32.Parse(Metric[1]),
CitationFlow = Int32.Parse(Metric[2]),
RI = Int32.Parse(Metric[3]),
MJTopicsID = item.MJTopicsID,
UserTableID = UserTableID
};
ViewBag.newdomain = newclient;
return RedirectToAction("Index");
}
}
return RedirectToAction("Index");

}

最佳答案

您是否尝试过错误消息中提到的建议?
像这样?

 csv.configuration.HeaderValidated = null; 

关于c# - .NET CSV uploader 允许空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48369408/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com