Your questions is not clear.
I assume you want to export the data in gridview( which is fetched from database) to excel.
Then please try this article.
Export DataTable to Excel with Formatting in C#[
^]
You mentioned something about changing connection string. can you be bit more clear??