|
-
Nov 22nd, 2009, 06:26 PM
#1
Thread Starter
Addicted Member
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.
-
Nov 22nd, 2009, 06:34 PM
#2
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:
Dim table As DataTable = myDataSet.Tables("MyTable") Dim row As DataRow = table.Rows(0) 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.
-
Nov 22nd, 2009, 08:08 PM
#3
Thread Starter
Addicted Member
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.
-
Nov 22nd, 2009, 08:12 PM
#4
Re: Access to DataGridView for logic operation
 Originally Posted by Abrium
ok take it easy on me JM, I'm new to this remember.
You want more information? Less information?
-
Nov 22nd, 2009, 11:51 PM
#5
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|