how to convert datareader data into datatable
-
earlier i was using sqldataadapter = new SqlDataAdapter(cmd); sqldataadapter.fill(dataset) to get data from database, and use to bind it to datagrid. but as i do not use this datagrids for editing. i want to use datareader instead of dataset. The number of columns will not be fixed so i can not create datatable with fixed number of columns and fill it by iterating through datareader. i do not want to use ' sqldataadapter.fill(datatable); ' either. every suggestion welcome ..thanks in advance.
pallavi
-
earlier i was using sqldataadapter = new SqlDataAdapter(cmd); sqldataadapter.fill(dataset) to get data from database, and use to bind it to datagrid. but as i do not use this datagrids for editing. i want to use datareader instead of dataset. The number of columns will not be fixed so i can not create datatable with fixed number of columns and fill it by iterating through datareader. i do not want to use ' sqldataadapter.fill(datatable); ' either. every suggestion welcome ..thanks in advance.
pallavi
Pallavi, Firstly you have to provide structure to the datatable i.e. column names and datatypes.... Once you have the structure set you can loop through your datareader and add one row at a time to your DataTable. You can provide structure to your datatable even after you have data in your datareader!
Gautham
-
Pallavi, Firstly you have to provide structure to the datatable i.e. column names and datatypes.... Once you have the structure set you can loop through your datareader and add one row at a time to your DataTable. You can provide structure to your datatable even after you have data in your datareader!
Gautham
thank u gautam . but i have three different querries in switch case . and i am going to bind to datgrid according to selected criteria. so, according to u may i hv to make ready different datatables with the different structures? isnt it there any easy way as-- datatable= (datatable)datareader ; (kidding. but i want it as flexivble as dataset). thank u.
pallavi
-
earlier i was using sqldataadapter = new SqlDataAdapter(cmd); sqldataadapter.fill(dataset) to get data from database, and use to bind it to datagrid. but as i do not use this datagrids for editing. i want to use datareader instead of dataset. The number of columns will not be fixed so i can not create datatable with fixed number of columns and fill it by iterating through datareader. i do not want to use ' sqldataadapter.fill(datatable); ' either. every suggestion welcome ..thanks in advance.
pallavi
-
Why don't you want to use the DataAdapter.Fill method? If you want the data in a DataTable you will be doing the same thing as that method does anyway.
--- single minded; short sighted; long gone;
thank u guffa, though dataadapter.fill(........) uses datareader behind the scene, as per requirement i have to use datareader in my code. :( plz help. thanks in advance
pallavi
-
thank u guffa, though dataadapter.fill(........) uses datareader behind the scene, as per requirement i have to use datareader in my code. :( plz help. thanks in advance
pallavi