导入CSV文件使用OLEDB - 字符串数据类型?字符串、数据类型、文件、CSV

2023-09-06 22:14:35 作者:一念太执着

我正在写一个C#.NET Web应用程序,而用户将被上传到被处理的CSV文件。这些CSV文件包含了一些数据类型,而我在使用其中的一些麻烦。有一个在科学记数法(9.1234563E的+ 18,而不是91234563000000000000)得到进口的20位收据号字段,以及任何前导零的越来越下降。前导零也下降另外4位数字的门店数量领域。

I'm writing a C# .net web application, and users will be uploading CSV files to be processed. These CSV files contain a number of data types, and I'm having trouble with a few of them. There is a 20-digit receipt number field that is getting imported in scientific notation (9.1234563E+18 instead of 91234563000000000000), and any leading zeros are getting dropped. Leading zeros are also dropped in another 4-digit store number field.

我读过有关创建Schema.ini文件来定义数据类型,而每个文件都会有一个不同的文件名,这意味着我不得不以编程方式生成一个新的模式文件,并且由于多个用户可以使用应用程序同时,这样的规则,该选项了。

I've read about creating a Schema.ini file to define the datatypes, but each file will have a different file name, meaning I'd have to generate a new Schema file programmatically, and since multiple users may be using the application simultaneously, it kind of rules this option out.

没有任何人有什么建议?

Does anybody have any advice?

推荐答案

这听起来像是你将不得不写一些自定义的code表示手动读取文件,并自行分割等领域。您可以轻松地在同一时间读取一行,并使用String.Split方法来获取各个字段。当然,这是假设的CSV文件将永远是相同的格式,所以你可以处理每个字段以同样的方式,不管该文件的来源。这种方式可以处理每个领域正是你想要的方式来。

It sounds like you will have to write some custom code that reads the files manually and split the fields yourself. You can easily read in a line at a time and use the String.Split method to get the individual fields. Of course this is assuming the CSV files will always be in the same format so you can process each field the same way no matter where the file comes from. This way you can process each field exactly the way you want to.