Datareader vs Dataset
I'm having a method that exports content from the database to excel file开发者_开发问答s. The method taks as paramaters a DataReader param and a int param - the number of rows. For the number of rows i'm using a dataset, wich i fill using the same query as for the datareader. So I'm executing it twice... Is there a way I can avoid that? Can I somehow get the number of rows from the datareader ?
Thanks!
Its better to change the query and add an extra column by using ROW NUMBER () function of SQK SERVER.It will get the number for each row u selected.Use a DataTable to hold the values which you got after executing the select query. So you will have an extra column in your datatable and just use the column you just print how many rows you want to print.So in a for loop it is possible to print the coloumns from starting index to endindex.
The last column of dataTable will contains how many rows selected by executing the query.
I hope your problem will solve by this method
精彩评论