Last active
August 29, 2015 13:57
-
-
Save nisar1/9651598 to your computer and use it in GitHub Desktop.
filling a datatable or dataset the quick way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private DataTable GetDataTable() | |
{ | |
string sql = "SELECT Id, Description FROM MyTable"; | |
using (SqlConnection myConnection = new SqlConnection(connectionString)) | |
{ | |
using (SqlCommand myCommand = new SqlCommand(sql, myConnection)) | |
{ | |
myConnection.Open(); | |
using (SqlDataReader myReader = myCommand.ExecuteReader()) | |
{ | |
DataTable myTable = new DataTable(); | |
myTable.Load(myReader); | |
myConnection.Close(); | |
return myTable; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment