I'm making my owner sas data viewer in a custom task(C#), and the format need to be applied.
I refered to "SAS® 9.4 Providers for OLE DB Cookbook" and "Sample 26145: Visual Studio 2005 Visual Basic Code Snippets".
Here is my code.
var adoConnection = new ADODB.Connection();
var adoRecordset = new ADODB.Recordset();
var adoCommand = new ADODB.Command();
var server = new SasServer(Consumer.AssignedServer);
var connectString = "provider=SAS.IOMProvider.1; SAS Workspace ID={0}";
adoConnection.Open(string.Format(connectString, server.GetWorkspaceIdentifier()), "", "", 0);
adoCommand.ActiveConnection = adoConnection;
adoCommand.CommandText = "select * from sashelp.class";
adoCommand.CommandType = ADODB.CommandTypeEnum.adCmdText;
adoCommand.Properties["SAS Formats"].Value = "_ALL_";
//adoRecordset.Properties["SAS Formats"].Value = "_ALL_";
adoRecordset.Open(adoCommand, System.Reflection.Missing.Value, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockReadOnly, 1);
//Fill an ADO.NET DataSet using the ADODB Recordset
var adapter = new OleDbDataAdapter();
var dataTable = new DataTable();
var count = adapter.Fill(dataTable, adoRecordset);
sasDataGridView1.DataSource = dataTable.DefaultView;
adoRecordset.Close();
Marshal.ReleaseComObject(adoRecordset);
adoConnection.Close();
Marshal.ReleaseComObject(adoConnection);
But it doesn't work. The DataGridView shows nothing. If I change sashelp.class to sashelp.cars, I got a "At least one of the IDs values (element 2 which is -1) is invalid." exception.
Am I missing something?
Shen
... View more