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
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