It looks like you are recreating the file within the loop, so your line:
System.IO.StreamWriter file= new System.IO.StreamWriter("example.txt");
file.WriteLine(result);
Is overwriting the file every time.
According to StreamWriter documentation:
If the file exists, it is overwritten; otherwise, a new file is created.
This may not be optimal, but to fix it try this code:
System.IO.StreamWriter file= new System.IO.StreamWriter("example.txt");
while(reader.Read())
{
string x1 = (string) reader["x1"];
string x2 = (string) reader["x2"];
string x3 = (string) reader["x3"];
string x4 = (string) reader["x4"];
result= x1+","+x2+","+x3+","+x4+;
file.WriteLine(result);
}
file.Close();