public DataTable GetDataTable(){DataTable dataTable = new DataTable();using (SqlConnection conn =new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString)){SqlCommand cmd = conn.CreateCommand();cmd.CommandText = "procedure_name";cmd.CommandType = CommandType.StoredProcedure;// SqlDataReader need an open conncetion, so check and open it.if (conn.State != ConnectionState.Open)conn.Open();// Read data by using Execute ReaderSqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);//Use data table load method to load data from data readerdataTable.Load(dr);}return dataTable;}
Wednesday, 10 April 2019
Load datareader to datatable
Subscribe to:
Posts (Atom)