Solved

VB .net MySQL - Getting field names and valuse for each row in each field.

Posted on 2010-11-09
8
872 Views
Last Modified: 2012-05-10
Here is the cod I am using to get data from mysql and it does populate the DataGrid.  But how do I get individual row/field information assigned to a variable?  How do I get total rows returned?
 If connected Then
            Try
                'MsgBox("Viewing") ' debugging
                data = New DataTable

                dataAdap = New MySqlDataAdapter("SELECT * FROM events", conn)
                cmdBuild = New MySqlCommandBuilder(dataAdap)

                dataAdap.Fill(data)

            Catch ex As Exception
                MsgBox("Error COnnecting To The Database!" & ex.Message.ToString())
            End Try
            frmMain.dataGrid.DataSource = data

        End If

Open in new window

0
Comment
Question by:keith1001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 250 total points
ID: 34097101
Hi,

You can do a for loop agains tyou Datagrid like this

        Dim drRow As DataGridViewRow
        For Each drRow In frmMain.dataGrid.Rows
            MsgBox(drRow.Cells(0).Value)
        Next

Where you can change the Cells(0) can be the number of columns of the datagridview. To know the total rows returne use this

frmMain.dataGridRows.Count

Or you can do the same with the Datatable

        Dim drRow As DataRow
        For Each drRow In data.Rows
            MsgBox(drRow(0))
        Next

and fo the total rows returned

data.Rows.Count

0
 
LVL 7

Assisted Solution

by:rogerard
rogerard earned 250 total points
ID: 34097141
msgbox("Rows: " &  data.Rows.Count)

     For Each row As DataRow In tdtAHCS.Rows
                For Each col As DataColumn In tdtAHCS.Columns
                 ...
                Next
              Next


0
 

Author Comment

by:keith1001
ID: 34101246
Thanks guys for your help!  Both of you guys helped me out, so will accept both solutions.  

I have one last question though, how do I get the field names?
0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 7

Expert Comment

by:rogerard
ID: 34101453
col.ColumnName.ToString
0
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 34101980
If you are using the Datagridview will be

DataGridView1.Columns(0).DataPropertyName
0
 

Author Comment

by:keith1001
ID: 34102242
I am trying to get the database field names.

I did this, but dont get anything:

Dim col As DataColumn
Dim myfield As String

myfield = col.ColumnName.ToString()
MsgBox("Column Name" & myfield)
0
 
LVL 7

Assisted Solution

by:rogerard
rogerard earned 250 total points
ID: 34102315
You need to do this
If connected Then
            Try
                'MsgBox("Viewing") ' debugging
                data = New DataTable

                dataAdap = New MySqlDataAdapter("SELECT * FROM events", conn)
                cmdBuild = New MySqlCommandBuilder(dataAdap)

                dataAdap.Fill(data)

     For Each col As DataColumn In data.Columns
                 msgbox("Column Name" & col.columnname.tostring)
      Next

            Catch ex As Exception
                MsgBox("Error COnnecting To The Database!" & ex.Message.ToString())
            End Try
            frmMain.dataGrid.DataSource = data

        End If

 
0
 
LVL 13

Assisted Solution

by:gamarrojgq
gamarrojgq earned 250 total points
ID: 34102317
You are getting the right property but your COL object needs to be associated with your datatabe like this (using DATA as your datatable just like your first code example)


Dim col As DataColumn
Dim myfield As String

For Each col In data.Columns
     myfield = col.ColumnName.ToString()
     MsgBox("Column Name" & myfield)
Next
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question