# NMath User's Guide

37.1 Creating ADO.NET Objects from Vectors and Matrices (.NET, C#, CSharp, VB, Visual Basic, F#)

Real-value NMath vector and matrix classes provide ToDataTable() methods for creating ADO.NET DataTable objects. Complex number vector and matrix classes provide paired methods ­ToRealDataTable() and ToImagDataTable() for creating DataTable objects containing the real and imaginary parts, respectively.

NOTE—Values are copied by all methods that create data tables.

For example, this code creates a data table of one column containing the values in a vector:

Code Example – C#

```using System.Data;

var v = new FloatVector( "45.4 -0.032 99 2.34" );
DataTable table = v.ToDataTable();
```

Code Example – VB

```Imports System.Data

Dim V As New FloatVector("45.4 -0.032 99 2.34")
Dim Table As DataTable = V.ToDataTable()
```

By default, the table is named Table. You can also pass a non-default table name to the ToDataTable() method. Thus, this code creates a data table named MyMatrixTable containing the values in a DoubleMatrix:

Code Example – C#

```using System.Data;

var A = new DoubleMatrix( 8, 5, 3.1415 );
DataTable table = A.ToDataTable( "MyMatrixTable" );
```

Code Example – VB

```Imports System.Data

Dim A As New DoubleMatrix(8, 5, 3.1415)
Dim Table As DataTable = A.ToDataTable("MyMatrixTable")
```

This code illustrates creating paired data tables containing the real and imaginary parts a FloatComplexMatrix:

Code Example – C#

```using System.Data;

string s =
"2 x 2 [ (4.54,9.78) (3.2,-4.78) (-4.32,2.23) (4.3234,-1.0) ]";
var A = new FloatComplexMatrix( s );

DataTable reals = A.ToRealDataTable( "RealParts" );
DataTable imags = A.ToImagDataTable( "ImaginaryParts" );
```

Code Example – VB

```Imports System.Data

Dim S As String =
"2 x 2 [ (4.54,9.78) (3.2,-4.78) (-4.32,2.23) (4.3234,-1.0) ]"
Dim A As New FloatComplexMatrix(S)

Dim Reals As DataTable = A.ToRealDataTable("RealParts")
Dim Images As DataTable = A.ToImagDataTable("ImaginaryParts")
```

By default, the columns in a data table created from a vector or matrix are named column1, column2, and so on. If you wish to specify non-default column names, call Columns() on the returned DataTable object to obtain a DataColumnCollection, then iterate over the collection and set the ColumnName property on each DataColumn object to the desired name.

Top

Top