0

hi, i started using VB 2008 recently (with perl background, its a big leap) and having a problem with database.
i am trying to access a database that is attached to a different form. i managed to get my code to work if i was writing on the same form.

example of code that will work just fine

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    For Each row As DataRow In Contact_dataDataSet1.ContactTable.Rows
        If row.Item("LastName").Equals("Singer") Then
            MessageBox.Show(" name = " & row.Item("FirstName"))
        End If
    Next
End Sub

however, when i use the same code on another form, nothing happens although there are no errors. what is troubling is that the msgbox for "hello world" did not even show up. i guess there is a syntax error in my for each loop

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    For Each row As DataRow In form2.Contact_dataDataSet1.ContactTable.Rows
        MsgBox("hello world!!!")
        If row.Item("LastName").Equals("Singer") Then
            MessageBox.Show(" name = " & row.Item("FirstName"))
        End If
    Next
End Sub

in addition to that, suppose i do not want to loop through the whole database to find lastname = singer, how am i able to obtain the firstname or singer? in Perl i would have used hashes. something like print $contacts{"firstname"}{$lastname};

Edited by eongchin: change **form2** to form2. some reason the bold did not show up.

3
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by adam_k
0

Do you have Contact_dataDataSet1 modifier set to public or friend? If it's private then you can't reference it outside it's class/module. If it's friend then you can access it within the same project and if it's public then you can access it from anywhere.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.