Results 1 to 5 of 5

Thread: Access to DataGridView for logic operation

  1. #1

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Access to DataGridView for logic operation

    I have created a DB connection, loaded my data grid and am looking to perform accumulation on the salaries that are shown. However it won't give me access to my grid view or the table for the Row.

    This is the code that I have. The loop and the accumulator is at the bottom.

    Code:
            If rdoFullTime.Checked = True Then
                'Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=C:\Users\Isabella\Desktop\AdoExample\bin\Company2.mdb")
                ' By RM: yes, this is an absolute path. They will always make you a problem.
                '        Always use a relative path.
                Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=..\Company2.mdb")
                ' By RM: I have included the Full-Time column just to easily test the result of the query.
                '        You could certainly remove it later if you wish.
                Dim cmd As OleDbCommand = New OleDbCommand("SELECT Last_Name, First_Name, Salary, Full_Time FROM SalesStaff WHERE Full_Time = Yes", con)
                con.Open()
                Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
                Dim myDataSet As DataSet = New DataSet()
                myDA.Fill(myDataSet, "MyTable")
                dgvAdoExample.DataSource = myDataSet.Tables("MyTable").DefaultView
                con.Close()
    
                Dim decTotal As Decimal
                Dim Counter As Integer = 0
                Dim Row As (NEED HELP HERE)
                For Each Row In (NEED HELP HERE)
                    decTotal += Row.Salary
                    Counter += 1
                Next
                lblAverage.Text = FormatCurrency(decTotal / Counter)
    
            End If
    I tried to dim the Row as myDA.Row and myDataSet.Row and it won't allow me to and I can't figure out why. I know this deals with database but the problem is the logic not the database.
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Access to DataGridView for logic operation

    DataAdapters don't have rows and neither do DataSets. A DataAdapter is simply for retrieving and saving data. It doesn't store the data. A DataSet is a container for DataTables and DataRelations. If you want to access the data then you need to get the DataTable from the DataSet, then get the DataRow from the DataTable, then get the data from the DataRow, e.g.
    vb.net Code:
    1. Dim table As DataTable = myDataSet.Tables("MyTable")
    2. Dim row As DataRow = table.Rows(0)
    3. Dim lastName As String = CStr(row("Last_Name"))
    By the way, this is pointless:
    Code:
    dgvAdoExample.DataSource = myDataSet.Tables("MyTable").DefaultView
    When you bind a DataTable, the data is automatically taken from its DefaultView anyway.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: Access to DataGridView for logic operation

    ok take it easy on me JM, I'm new to this remember.
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Access to DataGridView for logic operation

    Quote Originally Posted by Abrium View Post
    ok take it easy on me JM, I'm new to this remember.
    You want more information? Less information?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: Access to DataGridView for logic operation

    Working with what I got currently. There isn't a lot of information on the web with what I would consider CLR integration. Having to figure this out on my own.
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width