A DataTable is a virtual representation of a table in a database. It can have multiple columns and multiple rows. It is equivalent to an EViews workfile where each column in the table is represented as a series object in the workfile.
Our COM methods Put, PutSeries, and PutGroup, do not currently support reading a passed in DataTable or Dataset object. We only support reading Excel Range objects and 1 or 2 dimensional arrays.
Because of this, to get the data out of a DataTable and into EViews requires that you convert each column into a 1-dimensional array. Once you have the array, you can call PutSeries with that array and the name of the column as the series name.
Here's an example of doing this in VB.NET. Assume the variable 'ds' is the Dataset object that contains one DataTable that you'd like to push to EViews. In this example, I create a new undated workfile that has the same number of rows as found in the DataTable to store the data.
VB.NET Example:
Code: Select all
'launch or connect to EViews
Dim mgr As New EViews.Manager
Dim app As EViews.Application = mgr.GetApplication(EViews.CreateType.ExistingOrNew)
'for debugging only, show EViews
app.Show()
'create an undated workfile with the right number of observations
app.Run("create u " & ds.Tables(0).Rows.Count.ToString)
For Each col As DataColumn In ds.Tables(0).Columns
Dim al As New ArrayList(ds.Tables(0).Rows.Count)
For Each row As DataRow In ds.Tables(0).Rows
al.Add(row(col)) 'DBNull values are ok here
Next
Try
app.PutSeries(col.ColumnName, al.ToArray())
Catch ex As Exception
MsgBox(ex.Message)
End Try
Next
'clean up
app = Nothing
mgr = Nothing
GC.Collect()
Now if the DataTable contains only columns of a single data type (all numeric, or all string), then you could push everything into EViews at once by converting the DataTable into a 2-dimensional array, then calling PutGroup with the data, along with the column names.
We'll most likely add support for reading DataTable objects directly in the future. But until then, this workaround should suffice.
Steve
