datatable.compute("Sum(Convert
datatable.compute("Sum(Convert
datatable.compute("Sum(Convert
datatable.compute("Sum(Convert
datatable.compute("Sum(Convert
datatable.compute("Sum(Convert datatable.compute("Sum(Convert datatable.compute("Sum(Convert datatable.compute("Sum(Convert datatable.compute("Sum(Convert datatable.compute("Sum(Convert datatable.compute("Sum(Convert datatable.compute("Sum(Convert
datatable.compute("Sum(Convert datatable.compute("Sum(Convert
datatable.compute("Sum(Convert
Go Back  Xtreme Visual Basic Talk > > > datatable.compute("Sum(Convert


Reply
 
Thread Tools Display Modes
  #1  
Old 10-25-2009, 09:28 PM
billyboy630 billyboy630 is offline
Newcomer
 
Join Date: Sep 2009
Posts: 14
Default datatable.compute("Sum(Convert


I need help with this line of code: Me.avgsalespricetxt.Text = Me.dtsold.Compute("AVG(Convert([Selling Price]),'System.Int32'))")

Here is all the code i have so far, I need to Average a column in my datatable from what i have read "Compute method supports expressions and they support CONVERT function that you could use inside of the expression."

But i cant get the line of code correct

Code:
Imports System.Data.OleDb
Imports System.Collections


Public Class Subject_Values
    Dim builder As New System.Data.OleDb.OleDbConnectionStringBuilder
    Dim con As New OleDb.OleDbConnection(builder.ConnectionString)
    Dim dtlist As New DataTable
    Dim dtsold As New DataTable
    Dim dtlistreo As New DataTable
    Dim dtavgsold As New DataTable

    Private Sub BuildConnectionString()
        builder("Provider") = "Microsoft.Jet.OLEDB.4.0"
        builder("Data Source") = IO.Path.GetDirectoryName(Me.OpenFileDialog1.FileName)
        builder("extended properties") = "text;HDR=YES;FMT=Delimited\"
    End Sub
    Private Sub SetConnString()
        con = New OleDb.OleDbConnection(builder.ConnectionString)
    End Sub
    Private Sub ClearData()
        dtlist.Clear()
        dtsold.Clear()

    End Sub
    Private Sub CreateDataSet()
        Dim comm As New OleDb.OleDbCommand("Select * From " & Me.OpenFileDialog1.SafeFileName & " Where Status  <> 'S'", con)
        Dim dalist As New OleDbDataAdapter(comm)
        Dim comm1 As New OleDbCommand("SELECT * FROM " & Me.OpenFileDialog1.SafeFileName & "  Where Status = 'S'", con)
        Dim dasold As New OleDbDataAdapter(comm1)
        Dim comm2 As New OleDbCommand("Select Int([Selling Price]) From " & Me.OpenFileDialog1.SafeFileName & "  Where Int([Selling Price]) > '0' ", con)
        Dim daavgsold As New OleDbDataAdapter(comm2)

        dalist.Fill(dtlist)
        dasold.Fill(dtsold)
        daavgsold.Fill(dtavgsold)

        Me.avgsalespricetxt.Text = Me.dtsold.Compute("AVG(Convert([Selling Price]),'System.Int32'))")

        Me.BindingSource7.DataSource = dtavgsold
        Me.BindingSource1.DataSource = dtlist
        Me.BindingSource2.DataSource = dtlist
        Me.BindingSource3.DataSource = dtlist
        Me.BindingSource4.DataSource = dtsold
        Me.BindingSource5.DataSource = dtsold
        Me.BindingSource6.DataSource = dtsold
        Me.ComboBox1.DataSource = Me.BindingSource7
        Me.ComboBox1.DisplayMember = "Bedrooms"
        MsgBox(TypeName(ComboBox1.DisplayMember))
Reply With Quote
  #2  
Old 10-26-2009, 11:12 AM
IUnknown's Avatar
IUnknown IUnknown is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Oct 2004
Location: Montréal
Posts: 1,135
Default

From what I've tried, no, you cannot perform any action like multiplication or addition or use a function like CONVERT inside the aggregate function of the expression you will use in the .Compute() method.

You could create another column which applies the CONVERT function and then compute your aggregate value on that column.

HTH,
<iunknown />
__________________
win7 : vs 2008 : .Net 3.5
Reply With Quote
  #3  
Old 10-26-2009, 09:14 PM
billyboy630 billyboy630 is offline
Newcomer
 
Join Date: Sep 2009
Posts: 14
Default

Thats what its looking like, could you give me an example of how i would do that with the code i have. If I understand correcctly i would create a new column from the exisitng column and change the data type from string to integer?
I don't know how i would go about doing that, I am learning as I go
Reply With Quote
  #4  
Old 10-27-2009, 02:33 PM
IUnknown's Avatar
IUnknown IUnknown is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Oct 2004
Location: Montréal
Posts: 1,135
Default Using Expressions in DataColumn.Compute

The example code below creates a new DataColumn that holds integer values converted from text values by an expression. The mean value for this column is then computed.

Code:
' Create a column to hold integer values
Dim col As DataColumn = New DataColumn("computedValue", GetType(System.Int32))

' Specify a suitable expression
col.Expression = "Convert([Selling Price], 'System.Int32')"

' Put the new column into the appropriate DataTable
dtsold.Columns.Add(col)

' Compute your value
Me.avgsalespricetxt.Text = dt.Compute("AVG(computedValue)", "").ToString
HTH,
<iunknown />
__________________
win7 : vs 2008 : .Net 3.5
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
datatable.compute(&quot;Sum(Convert
datatable.compute(&quot;Sum(Convert
datatable.compute(&quot;Sum(Convert datatable.compute(&quot;Sum(Convert
datatable.compute(&quot;Sum(Convert
datatable.compute(&quot;Sum(Convert
datatable.compute(&quot;Sum(Convert datatable.compute(&quot;Sum(Convert datatable.compute(&quot;Sum(Convert datatable.compute(&quot;Sum(Convert datatable.compute(&quot;Sum(Convert datatable.compute(&quot;Sum(Convert datatable.compute(&quot;Sum(Convert
datatable.compute(&quot;Sum(Convert
datatable.compute(&quot;Sum(Convert
 
datatable.compute(&quot;Sum(Convert
datatable.compute(&quot;Sum(Convert
 
-->