Datareader Question

Results 1 to 2 of 2

Thread: Datareader Question

  1. #1
    Join Date
    Dec 1969

    Default Datareader Question

    There has to be a simple way to reset an instance of SqlDataReader. In otherwords, I need to generate a file with the results from a stored proc., and then display the results in a data bound grid. There doesn't seem to be a Reset() or MoveFirst() type method. Any insight? Thanks in advance.

  2. #2
    Join Date
    Dec 1969

    Default RE: Datareader Question

    Here is one example.....A reader is setup for forward only-motion. It is extremely fast. It is meant to get the results from sql and display them. If you need to move up from one record back to the previous record I would recommend using a dataset.<BR><BR>Here is an example that might help...<BR><BR>&#039;no Caching of any Data ...take the data from sql and display it<BR> Dim ConnectSql as SqlConnection<BR> Dim ConnectCommand as SqlCommand<BR> Dim ConnectRecordSet as SqlDataReader<BR><BR> lbl_Company.text = lbl_Company.text + "&#060;br/&#062;Version 1&#060;br/&#062;"<BR> ConnectSQL = New SqlConnection(Application("SQLConnectionString"))< BR> ConnectCommand = New SqlCommand("Proc_CompaniesAtoZ",ConnectSQL)<BR> With ConnectCommand<BR> .CommandType = CommandType.StoredProcedure<BR> ConnectSql.Open()<BR> ConnectRecordSet = .ExecuteReader()<BR> &#039;doing a read here increments it to record number 2<BR> &#039; so we never get to see record number 1<BR> &#039;If ConnectRecordSet.Read() then<BR> &#039; this is the old style of used in asp. the only<BR> &#039;reason you would want to use the above is if &#039; &#039; you are analyzing each record for specific values<BR><BR> with Lst_Companies<BR> .DataSource = ConnectRecordSet<BR> .DataValueField = "CompanyID"<BR> .DataTextField = "CompanyName"<BR> .DataBind<BR> end with<BR> ConnectRecordset.Close()<BR> ConnectSql.Close()<BR> End With<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts