Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to read data from multiple csv files. filter then merge common data in another sql database asp.net ?

eg.
read from csv file sample1- roll no, name , age (database1)
read from csv file sample 2- rollno , name, address. (database2)

store data in sql database
output - roll no, name , age address (database3)finall one
Posted

This is a pseudo code variant for how to do it

1. Open the file with e.g. StreamReader sr = File.OpenText()
2. In a loop read the file line by line with string line = sr.ReadLine()
3. Split the line into parts with string[] parts1 = line.Split(',')
4. Store the parts into a DataTable with the column names you want and RollNo as primary key
5. Repeat for file two and find an existing row using RollNo and update that row with Address.
6. Create SqlConnection and open the database
7. Create a SqlCommand object
8. Loop through the rows in the DataTable and get a DataRow dr for each row.
9. Create the SQL command string, like
C#
String.Format("INSERT INTO MyTable ('RollNo', 'Name', 'Age', 'Address') VALUES ({0}, {1}, {2})", dr["RolNo"], dr["Name"], dr["Age"], dr["Address"]]);

10. Execute a non query
11. Repeat for next row


There are plenty of other ways to do it as well.

Search for
* How to read data from a comma separated file
* How to insert data into a SQL database
 
Share this answer
 
v3
Comments
10923679 10-Jul-14 6:49am    
thank you so much for this..
any i am new with asp.net.
can u help with more detail code..
only with seaching particular value
like roll no with be unique to search n filter the data from text and also merge in table.
roll no or bill no or any code.
roll like
A100
A101
A103
how will i search from csv text file in asp.net
can u help me with more code in asp.net in this ..
 
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