Hi Dw.

I have a MySql server database, and I'm polling data from the database. The problem I'm getting is that when I'm retrieving users activities I only get the first record only which is on Row(0) or the first record with that username. Suppose I have a database like this:

 `-------------------------------------------------
 |Activity     | ActUser      |Username  |
  -------------------------------------------------
 |working    |John             |Steve          |
  --------------------------------------------------
 |done         |thabo           |tomas         |
  -------------------------------------------------
 |confirmed|amanda        |Steve          |
  -------------------------------------------------`

Now the problem is retrieving all records with username (Steve). In the above example it should be 2 records retrieved one with John and another with amanda.

This is what I have:

 Try
 Dim dav As New MySqlDataAdabter(("select * from mydatabase.test where Username ='" & yUsername & "'"), rtConn)
 Dim dvt As New DataTable
 dav.Fill(dvt)
 If dvt.Rows.Count > 0 Then
 yActivity = dvt.Rows(0).Item("Activity") & ""
 yActUser = dvt.Rows(0).Item("ActUser") & ""
 REM: I send this data to the client like this:
 Dim resp As String
 resp = "YTREWQ:<" & yActivity & ">:<" & yActUser & ">"
 sendMessage(resp)
 End If
 Catch ex As Exception
 ErrorLog(ex.Message & vbCrLf)
 End Try

Any help here because currently I only receive the first record for this user which is the record with John in this case I don't receive with that amanda.

What am I missing/doing wrong here?

Recommended Answers

All 4 Replies

Oops I can see that the table got mixed, basically its a database table with 3 columns, 3 records.

Any help?

I see an if statement that checks whether you have a result, but no loop to handle more than the first result.

Thanks that was my problem on how I could loop through this, I knew I need to loop through it but didn't know how because when I try For Each MyRow As DataRow In dvt.Rows it didn't do what I wanted till I find this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.