37.2 Creating Vector and Matrices from ADO.NET Objects (.NET, C#, CSharp, VB, Visual Basic, F#)
You can construct NMath vector and matrix classes from standard ADO.NET database objects. Real-value vector and matrix class constructors accept DataTable, DataRow, DataRowCollection, and DataView objects, typically obtained from a database query. Complex number vector and matrix class constructors accept paired database objects containing the real and imaginary parts, respectively.
For example, assuming table is a DataTable instance:
Code Example – C#
var A = new DoubleMatrix( table );
Code Example – VB
Dim A As New DoubleMatrix(Table)
The resulting matrix has the same number of rows and columns as the data table. Note that all values must be able to be converted to a double through a cast. If not, the constructor throws an InvalidCastException.
Similarly, assuming view1 and view2 are DataView objects, this code creates a FloatComplexVector instance whose real parts are derived from the first column of view1, and whose imaginary parts are derived from the first column of view2:
Code Example – C#
var v = new FloatComplexVector( view1, view2 );
Code Example – VB
Dim V As New FloatComplexVector(View1, View2)
In this case, all values must be able to be converted to a float through a cast.