Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to import data in sql server using asp.net c# webapplication from txt file,in txt file column name are not define

here is data

31201805260758000100010002210001
31201805260758000100010003540001
31201805260759000100010001920001
31201805260805000100010000400001
31201805260808000100010002060001
31201805260808000100010001960001
31201805260809000100010001740001

Explain Field which will define in SQL server not in Txt file data.

31 20180526 0444 0002 000 2000091 0001

Date Time OUt Employe Code Machine ID

What I have tried:

looking for coding ,i tried to import data from excel to sql server now looking for coding of txt import into sql server using asp.net c#
Posted
Updated 2-Aug-18 1:16am
Comments
F-ES Sitecore 2-Aug-18 7:01am    
This isn't a site where you give vague requirements and people do your work for you. Break the problem down into smaller sections and tackle each section.

First you need to be able to read the file line by line - ReadLine

Each line then needs to be broken into it's fields - Substring

Once you have your fields you then insert into your database. That is also very well document so choose either ado.net or entity framework and google how to insert data using your chosen method.

1 solution

We don't do your work for you.
But here's how I'd do it:
1) Read the file into an array of strings: File.ReadAllLines will do that.
2) Set up a DataTable with the appropriate columns
3) Loop through each line
3.1) Use string.Substring to break the line into parts.
3.2) Use int.TryParse and DateTime.TryParseExact to convert the parts to "proper" datatypes.
3.3) Add the "proper" values to the DataTable as a new row.
4) Use a DataAdapter to write the DataTable to the DB.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900