C# 将文本文件中的一条记录插入3个表中
我有一个70行生成的文本文件。这是我的一个合作伙伴遗留平台的web表单,通过电子邮件发送给我,文本文件为:C# 将文本文件中的一条记录插入3个表中,c#,asp.net,sql-server-2008,C#,Asp.net,Sql Server 2008,我有一个70行生成的文本文件。这是我的一个合作伙伴遗留平台的web表单,通过电子邮件发送给我,文本文件为: Name First Name First Name + Name Age Telephone City Country Email Website Profession Etc Etc 2 ... 我想使用C和ASP.NET将此文本文件拆分为MS-SQL数据库中的3条记录 这3张表是这样的: Client_General_Information Client_Private_Infor
Name
First Name
First Name + Name
Age
Telephone
City
Country
Email
Website
Profession
Etc
Etc 2
...
我想使用C和ASP.NET将此文本文件拆分为MS-SQL数据库中的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个列表并插入其中的每一个?我只是想说清楚,我不想批量插入。每个文本文件都是唯一的客户端
谢谢创建一个单独的类,其getter和setter方法与3个表中的字段相同
Client_General_Information
Client_Private_Information
Client_Request_Problem
然后从文件中读取并将值指定给对象中的各个字段,如
依此类推,然后根据您对对象的要求将数据插入数据库。维护3个列表,并从文件中读取的位置插入循环中
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];