I really appreciate if you can share the link with your friends via Facebook,twitter,blog etc.

15 May 2011

SqlDataReader To DataTable

class ClsDataReaderToDataTable
{
    static void Main(string[] args)
    {
        string StrQuery = "SELECT * from MyTable";
        DataTable DtCustomers = new DataTable();
        using (SqlConnection oConn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionstring"].ConnectionString))
        {
            oConn.Open();
            SqlCommand SCmd = new SqlCommand(StrQuery, oConn);
            SqlDataReader SDr = SCmd.ExecuteReader();
            DtCustomers.Load(SDr);
        }
        Console.ReadKey();
    }
}