Solved

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

Posted on 2010-11-09
8
868 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net  Exporting Excel Woorkbook to PDF 7 69
Import a excel sheet in a grid 2 43
ASP.NET Load html part first, then start function 2 37
Code not executing correctly. 3 42
Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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