Results 1 to 2 of 2

Thread: loop through grid

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    loop through grid

    I'm getting an error msg on this line:

    For Each dr In ds.Tables("cards").Rows

    I have data in my grid, not sure why I'm getting this msg.

    An unhandled exception of type 'System.NullReferenceException' occurred in pcms.exe

    Additional information: Object reference not set to an instance of an object.

    VB Code:
    1. Dim cmdView As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter("select item_no, activity, account_no from pcms.pcms_item_activity where item_no='" & txtItem.Text & "' and activity='" & txtActivity.Text & "'", objCon)
    2.         ds = New DataSet()
    3.         cmdView.Fill(ds, "cards")
    4.         DataGrid1.DataSource = ds
    5.         DataGrid1.DataMember = "cards"
    6.         objCon.Close()
    7.  
    8.  Dim dr As DataRow
    9.         For Each dr In ds.Tables("cards").Rows
    10.             MsgBox("Whatever")
    11.         Next
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  2. #2
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Wink

    Not sure why you're getting the error, but the first thing that comes to my mind is why do you need to look at the datarow like that. I'd just look through the rows.....

    VB Code:
    1. 'Populate your DataSet using your own code, then ....
    2. Dim iMaxRec As Integer = DS.Tables("cards").Rows.Count
    3. If iMaxRec > 0 Then
    4.     For iLpr As Integer = 0 To iMaxRec - 1
    5.         msgbox "Sample: " & DS.Tables("cards").Rows(iLpr).Item("yourfieldnamehere")
    6.     Next iLpr
    7. End If
    ~Peter


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