3

I want Retrieve big Data from sql server. I want it load row by row and displaying in to DataGridView. That like i execute Sql Script in Sql server management studio 2005. How i do that?!

Dmitrii Lobanov
  • 4,897
  • 1
  • 33
  • 50
dungnn07
  • 31
  • 1
  • 2
  • no, that like: http://img690.imageshack.us/i/loadingresult.png/. In loading data process i want it display data available on DataGridView – dungnn07 Apr 07 '11 at 04:40

3 Answers3

0

use this query for paging

DECLARE @PageIndex int=1
DECLARE @PageSize int=10
DECLARE @StartRow int
DECLARE @EndRow int


SET @StartRow = (@PageSize * (@PageIndex - 1))  + 1  
SET @EndRow = @PageSize * @PageIndex + 1

SET NOCOUNT ON;

WITH ArticleSearch AS
(
    SELECT
       ROW_NUMBER() OVER 
         (
            -- Dynamic sorting
            ORDER BY       tablename.fieldname 


          ) AS RowNumber,   *


     FROM            tablename

)

-- Statement that executes the CTE
SELECT *
FROM
      ArticleSearch a
WHERE
      a.RowNumber BETWEEN @StartRow AND @EndRow - 1
ORDER BY
      a.RowNumber 

you can pass pageindex as argument to get which page you want to show and pagesize for total records in each page

Nighil
  • 4,099
  • 7
  • 30
  • 56
  • No, I don't want use paging. I wait data must load all on an dataGridView, and in loading process not completed yet, data available must displaying on gid. – dungnn07 Apr 07 '11 at 04:56
  • then you must query each row by paging and add each row by row to datagrid – Nighil Apr 07 '11 at 05:07
  • But that mean data must loaded before post to DataGridView. I want when all data not load completed yet, available data loaded must display on. – dungnn07 Apr 07 '11 at 05:41
0

You could use a SqlDataReader to do that, I am quite sure it is used in the SSMS. Every time you read a record (or a batch of records) from the reader, you display it in the user interface.

Do not forget to close the reader after reading is complete.

Johann Blais
  • 9,389
  • 6
  • 45
  • 65
0

You can try loading the Data using Backgroundworker class. And in the Progress update call you can update the DataGridview. Also the Progress indicator.

Check these links :

  1. http://geeknotes.wordpress.com/2007/09/19/using-backgroundworker-to-update-status/
  2. Using a Background Worker - Update a ProgressBar on the progress of a Recursive Method

It contains displaying directories using Backgroundworker.

Community
  • 1
  • 1
Anuraj
  • 18,859
  • 7
  • 53
  • 79