Hi,
Please refer following code.
1) First, read the file line by line and save in list.
List<string> myValues = new List<string>();
string line;
// Read the file and display it line by line.
System.IO.StreamReader file =
new System.IO.StreamReader("c:\\test.txt");
while((line = file.ReadLine()) != null)
{
myValues.Add(line);
}
2) Then open a DB-Connection to your DB via OleDB and insert the values into your database via an INSERT INTO Statement.
private void InsertMyValue(string myValue){
dbconnection.Open();
string setValues = "INSERT INTO YourTable(myColumn) VALUES ('" + myValue+ "');";
OleDbCommand cmd = new OleDbCommand(setValues, dbconnection);
cmd.ExecuteNonQuery();
dbconnection.Close();
}
3) Then call the method in a foreach - clause
foreach(string myLine in myValues){ //Go through the List with all the Lines
dbconnection.InsertMyValue(myLine); //Get every item in the List and call the Insert-Method
}
You can refer link
http://stackoverflow.com/questions/14922360/insert-data-from-a-text-file-into-a-table-in-c-sharp
Thanks,
Bh@gyesh