3 Replies - 6055 Views - Last Post: 25 May 2010 - 12:30 PM Rate Topic: -----

#1 TADS   User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 161
  • Joined: 09-August 08

for each field in mysql table

Posted 08 May 2010 - 02:07 AM

hi all,

still having problems with mysql... im trying to find out how i can you a for each statement when getting data from mysql table...

i have a table with IP and Port fields in... i want to get each and every one of the ip's and use it...

for each ip in heat table
and then run my "query()" function

how can i do this in vb.net?... i can get ALL ips and ports and put in a gridview but would like to use the ip and display the Game Server Data that my query() function gets...this is from a while back when i made my Game Server Browser and just tryiong to make a better way of keeping my ip and port data and mysql seams to be the best way as its online and it can be added to and edited as and when needed and no one has to "redownload" anything

Thanks for you time

Kev

Is This A Good Question/Topic? 0
  • +

Replies To: for each field in mysql table

#2 TADS   User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 161
  • Joined: 09-August 08

Re: for each field in mysql table

Posted 25 May 2010 - 07:52 AM

im still having problems with this and cant find a fix... i will give you some code... this is how i get the data i want....

    Public Sub connectionmysql()
        Dim conn As MySqlConnection
        conn = New MySqlConnection
        conn.ConnectionString = "Database=" + info.DB + ";" & _
                   "SERVER=" + info.server + ";" & _
                   "UId=" + info.Uid + "; Password= " + info.pass + ";"
        Dim commandtext As String
        Dim adapter As MySqlDataAdapter
        Dim table As DataTable

        ds = New DataSet()
        commandtext = "select ip from ips;"
        Try

            adapter = New MySqlDataAdapter(commandtext, conn)
            table = New DataTable
            adapter.Fill(table)

            DataGrid1.DataSource = table
            PopulateDataGridView()
        Catch ex As Exception
            MsgBox(ex.ToString)

        End Try

    End Sub



thats fine but still cant use each line of data from the datagrid... or is there some other way i could store data online like on a site and have the data updated if someone adds an ip and used each time someone runs the server lister?

thanks for your help

Kev
Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1730
  • View blog
  • Posts: 5,709
  • Joined: 25-September 09

Re: for each field in mysql table

Posted 25 May 2010 - 10:19 AM

You can use this to get to individual cells based on the iteration of the for each statement.

        For Each row As DataGridViewRow In DataGridView1.Rows
            MessageBox.Show(row.Cells(1).Value)
        Next


So what it is doing is moving to each row and displaying a messagebox to show the value that is contained in the column2 cell for that row. (remember, cells(0) is actually the first column because they start at 0 so keep that in mind. you would of course replace the messagebox line with the code to run your query using row.Cells(?).Value as the variable for the query parameter.
Was This Post Helpful? 1
  • +
  • -

#4 TADS   User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 161
  • Joined: 09-August 08

Re: for each field in mysql table

Posted 25 May 2010 - 12:30 PM

hi and thanks for that it works i am now happy!!! thank yoy very much :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1