VB Database Example

← All NMath Code Examples

 

Imports System
Imports System.Data

Imports CenterSpace.NMath.Core

Namespace CenterSpace.NMath.Core.Examples.VisualBasic

  ' A .NET example in Visual Basic showing how to use ADO.NET data structures with matrices.
  Module DatabaseExample

    Sub Main()

      Console.WriteLine()

      ' Set up "database"
      Dim Table As New DataTable()
      Table.Columns.Add("column1", GetType(Double))
      Table.Columns.Add("column2", GetType(Double))
      Dim Values(1) As Object
      Values(0) = 4.5D
      Values(1) = 3.2D
      Table.Rows.Add(Values)
      Values(0) = -2.4D
      Values(1) = 99
      Table.Rows.Add(Values)

      ' Create matrix
      Dim A As New DoubleMatrix(Table)
      Console.WriteLine("A...")
      Console.WriteLine(A.ToTabDelimited())
      Console.WriteLine()

      ' Change matrix by incrementing
      DoubleMatrix.Increment(A)
      Console.WriteLine("A incremented...")
      Console.WriteLine(A.ToTabDelimited())
      Console.WriteLine()

      ' Refresh data table 
      Table = A.ToDataTable()

      ' Select rows where column1 is positive
      Dim Rows() As DataRow = Table.Select("column1 > 0")

      ' Make new matrix of resulting rows.
      A = New DoubleMatrix(Rows)
      Console.WriteLine("A from database...")
      Console.WriteLine(A.ToTabDelimited())

      Console.WriteLine()
      Console.WriteLine("Press Enter Key")
      Console.Read()

    End Sub

  End Module

End Namespace

← All NMath Code Examples
Top