Skip to content

Instantly share code, notes, and snippets.

@talkingdotnet
Created February 25, 2018 15:35
Show Gist options
  • Save talkingdotnet/6b500ec39dc074dc360b369b024e3464 to your computer and use it in GitHub Desktop.
Save talkingdotnet/6b500ec39dc074dc360b369b024e3464 to your computer and use it in GitHub Desktop.
private DataTable FetchData(string tableName)
{
using (SqlConnection conn = new SqlConnection(_connectionString))
{
string sQuery = "SELECT * FROM [" + tableName + "]";
using (SqlCommand command = new SqlCommand(sQuery, conn))
{
conn.Open();
command.CommandTimeout = 180;
DataAdapter da = new SqlDataAdapter(command);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
dt.TableName = tableName;
ds.Tables.Remove(dt);
return dt;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment