文本文件插入到数据库中,但我的分隔符ID为tilde [英] Text file insert into Database but my delimiter id tilde

查看:84
本文介绍了文本文件插入到数据库中,但我的分隔符ID为tilde的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好



我想将我的文本文件插入数据库。如果你有任何例子,请给我发给我。



我的数据是:



0000000002~AETNA INC~G~GP~N~0000002~N~No~Y~N~N~000000887~US~XE~21~1031~10~21~NO~Pseudo

0000000003~空气产品&化学品公司~G~GP~N~0000003~N~No~Y~N~N~0000008989~US~XE~21~807~8~21~NO~Pseudo

0000000004~ALBANY INTERNATIONAL CORP~H~GP~N~0000004~N~No~Y~N~N~000000197~US~XB~21~1412~14~22~NO~Pseudo

0000000007~ALLEGHENY ENERGY INC ~G~GP~N~0000007~N~No~Y~N~N~0000005274~US~XE~21~809~8~21~NO~Pseudo

0000000008~ALCOA INCORPORATED~G ~GP~N~0000008~N~No~Y~N~N~0000006969~US~XE~21~803~8~21~NO~Pseudo

Hi

I Want insert my text file into database. please give me if u have any examples send me.

My data is:

0000000002~AETNA INC~G~GP~N~0000000002~N~No~Y~N~N~0000002887~US~XE~21~1031~10~21~NO~Pseudo
0000000003~AIR PRODUCTS & CHEMICALS INCORPORATED~G~GP~N~0000000003~N~No~Y~N~N~0000003689~US~XE~21~807~8~21~NO~Pseudo
0000000004~ALBANY INTERNATIONAL CORP~H~GP~N~0000000004~N~No~Y~N~N~0000004197~US~XB~21~1412~14~22~NO~Pseudo
0000000007~ALLEGHENY ENERGY INC~G~GP~N~0000000007~N~No~Y~N~N~0000005274~US~XE~21~809~8~21~NO~Pseudo
0000000008~ALCOA INCORPORATED~G~GP~N~0000000008~N~No~Y~N~N~0000006769~US~XE~21~803~8~21~NO~Pseudo

推荐答案

文本文件中的数据非常清晰,似乎用波浪号(〜)分隔。您不能直接将此文本文件插入数据库;也许你想将其数据插入数据库。因此,按照以下步骤操作即可完成:

1.逐行读取文本文件

2.删除波形符清理数据。您可以通过用空格替换〜来做到这一点,但最好使用string.split来分割,使用〜作为拆分器。 string.split将允许您将数据分配给字符串数组,现在您的数据采用数组的形式。

3.创建插入查询,将数组中的数据分配给列。

4.将数据插入数据库。



以下链接可帮助您执行步骤:

http://msdn.microsoft.com/en-us/library/db5x7c0d.aspx [ ^ ]



http://www.dotnetperls.com/split [ ^ ]



http://msdn.microsoft.com/en-us/library/system.data.sqlclient。 sqldataadapter.insertcommand.aspx [ ^ ]
The data in the text file is very clear and seems it is separated by tilde (~). You can not directly insert this text file to a database; perhaps you want to insert its data into the database. So, follow the following steps and you will be done:
1. Read the text file line by line
2. Clean the data by removing tilde. You can do this by replacing ~ with a space, but better use string.split to split using ~ as the splitter. string.split will let you assign the data to a string array and now your data is in the form of an array.
3. create an insert query, assign the data from the array to the columns.
4. insert the data to the database.

Following links may help you perform your steps:
http://msdn.microsoft.com/en-us/library/db5x7c0d.aspx[^]

http://www.dotnetperls.com/split[^]

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.insertcommand.aspx[^]


这篇关于文本文件插入到数据库中,但我的分隔符ID为tilde的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆