Results 1 to 3 of 3

Thread: DataReader Problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    31

    DataReader Problem

    I want to fill FlexGrid With the records returned From Executing
    by SqlCommand but the problem is the FlexGrid Filled With Then
    First Record Only
    Is ther any way to move to next record , please advice
    VB Code:
    1. Dim mycmd As New SqlCommand("Select ItemID,ItemName,Quantity,unitPrice,Total,Remarks From Invoice_Details where InvID = " & txtInvID.Text & "", MyConn)
    2.         MyConn.Open()
    3.  
    4.         Dim myReader As SqlDataReader
    5.         myReader = mycmd.ExecuteReader
    6.  
    7.         Do While myReader.Read
    8.             Dim x As Integer
    9.             For x = 0 To Flex1.Rows - 1
    10.                 Flex1.set_TextMatrix(x, 1, myReader.GetValue(0))
    11.                 Flex1.set_TextMatrix(x, 2, myReader.GetString(1))
    12.                 Flex1.set_TextMatrix(x, 3, myReader.GetValue(2))
    13.                 Flex1.set_TextMatrix(x, 4, myReader.GetValue(3))
    14.                 Flex1.set_TextMatrix(x, 5, myReader.GetValue(4))
    15.                 Flex1.set_TextMatrix(x, 6, myReader.GetString(5))
    16.  
    17.             Next
    18.  
    19.         Loop
    20.  
    21.         myReader.Close()
    22.         MyConn.Close()

  2. #2
    Addicted Member Nigh™a®e's Avatar
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    175
    I allways use DataSets for this kind of things.

    I never used the DataReader myself

  3. #3
    Addicted Member
    Join Date
    Mar 2001
    Location
    Devon, UK
    Posts
    181
    Never seen loop with a DR. Just use While and End While

    While oDR.Read


    End While
    Wind and waves resolves all problems.

Posting Permissions

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



Click Here to Expand Forum to Full Width