我有一个生成的文本文件,包含70行。这是一个来自我的合作伙伴“遗留”平台的网页表单,它是通过电子邮件在文本文件上发送给我的:
Name
First Name
First Name + Name
Age
Telephone
City
Country
Email
Website
Profession
Etc
Etc 2
...我希望使用C#和ASP.NET将这个文本文件“分割”为我的MS数据库中的3个记录。
这3张表如下所示:
Client_General_Information
Client_Private_Information
Client_Request_Problem我想针对特定的行,针对特定的表和字段。例子:
Line 1 goes in Table 1 (Name field)
Line 2 goes in Table 1 (First name field)
Line 3 goes in Table 1 (...)
Line 4-5-6 goes in Table 3 ( 3 other fields)
Line 7-9 goes in Table 1 (2 other fields)
Line 10 goes in Table 2 (...)我正在搜索一种读取文本文件的方法,并将其插入到3个表中。文本文件总是有相同的行数,并且总是有相同的顺序。有时行是空的,但它在文件间发生变化。
所以我有我的文件阅读器,但我不知道下一步该去哪里:
//Load our text file
TextReader tr = new StreamReader("\\test.txt");
int NumberOfLines = 70;
//Make our array for each line
string[] ListLines = new string[NumberOfLines];
//Read the number of lines and put them in the array
for (int i = 0; i < NumberOfLines; i++)
{
ListLines[i] = tr.ReadLine();
}
//
tr.Close();我应该创建3个数组或3个列表并插入其中每个数组或列表吗?为了澄清,我不想“大量插入”。每个文本文件都是唯一的客户端!
谢谢
发布于 2013-12-21 11:23:25
创建一个单独的类,其getter和setter方法与3个表中的字段相同
Client_General_Information
Client_Private_Information
Client_Request_Problem然后从文件中读取并将值赋值给对象中的相应字段,如
..。
Client_General_Information newObject = new Client_General_Information ();
int NumberOfLines = 70;
//Make our array for each line
string[] ListLines = new string[NumberOfLines];
//Read the number of lines and put them in the array
for (int i = 0; i < NumberOfLines; i++)
{
ListLines[i] = tr.ReadLine();
}
newObject.Name=ListLines[0];
newObject.LastName=ListLines[1];然后,根据对象的要求,将数据插入数据库中。
https://stackoverflow.com/questions/20674769
复制相似问题