private void GetTextFile()
{
NpgsqlConnection npgsqlConnection = new NpgsqlConnection();
npgsqlConnection.ConnectionString = "Server=127.0.0.1;Port=5432;User
Id=postgres;Password=rutuparna;Database=Employee";
npgsqlConnection.Open();
NpgsqlCommand command = new NpgsqlCommand("Select * from employee_details", npgsqlConnection);
NpgsqlDataReader dataReader = command.ExecuteReader();
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(@"D:\Rutu\txtfile.txt", false, Encoding.UTF8))
{
while (dataReader.Read())
{
writer.WriteLine(dataReader[0] + "; " + dataReader[1] + ";" + dataReader[2] + ";" + dataReader[3]);
}
}
MessageBox.Show("Data fetched Properly");
}
Here I have done how to convert data into a text file.
Can somebody please give me the code of how to export Text File data to the SQL database using C# ?