Use an SqlDataAdapter to read it into a DataTable:
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
using (SqlDataAdapter da = new SqlDataAdapter("SELECT MyColumn1, MyColumn2 FROM myTable WHERE mySearchColumn = @SEARCH", con))
{
da.SelectCommand.Parameters.AddWithValue("@SEARCH", myTextBox.Text);
DataTable dt = new DataTable();
da.Fill(dt);
...
}
}
You can then use whatever you want to save the datatable as a text file:
Writing a DataTable to a CSV file[
^] is one way, but there are loads of other depending on what your text file shoudl contain.