The library allows for loading data from an SPSS-file in the form of an IDataReader, which allows you to fill a ADO.Net DataTable. You can use the following code to load the data from an SPSS-file into a WinForms DataGridView:

var dialog = new OpenFileDialog() { Filter = "SPSS File|*.sav" };
dialog.ShowDialog();
var stream = dialog.OpenFile();

using (var stream = dialog.OpenFile())
{
    var datareader = new SpssLib.DataReader.SpssDataReader(stream);
    var dt = new DataTable();
    dt.Load(datareader);
    this.dataGridView1.DataSource = dt;
}

If you want to get more SPSS-specific data (missing values, value labels etc.) from the file, you can also use the SpssDataTable class to do that.

var dataset = new SavFileLibrary.SpssDataset.SpssDataset(stream);
var typeFirstVar = dataset.Variables[0].MeasurementType;

Last edited Jun 28, 2011 at 4:12 PM by elmarj, version 4

Comments

No comments yet.