Hello all
I have SAS data file, now i want to read it using C#.NET with the help of Visual studio 2010, How can i read it.
I have tried below code but it throws exception as "The table could not be found or the index file is missing"
here is my code
DataSet sasDs = new DataSet();
String sasLibrary = @"D\a.sas7bdat";
OleDbConnection sas = new OleDbConnection("Provider=sas.LocalProvider; Data Source=" + sasLibrary);
OleDbCommand sasCommand = sas.CreateCommand();
sasCommand.CommandType = CommandType.TableDirect;
sasCommand.CommandText = "Select * from sas.a";//sasDataSet; //here i got error The table could not be found or the index file is missing
OleDbDataAdapter da = new OleDbDataAdapter(sasCommand);
da.Fill(sasDs);
sas.Close();
What i do to resolve the issue ? i think my table name is wrong ? how can i get table name ?
Please help.
Thanks in advance for your kind suggestion
Thanks
Koolprasad2003
You are using "TableDirect" to access to SAS data.
It means that the CommandText should contain only the table name.
i.e. if you have foo.sas7bdat file, your CommandText should be:
sasCommand.CommandText = "foo"
Hope it helps.
Nicola
@"D\a.sas7bdat";
->
@"D:\a.sas7bdat"; ?
I know this is an old post but I would like to explain something here,
right now it seems like current provider does not support SQL for this reason
the connectionString should contain the Folder where your .sas7bdat file is.
and then when creating the command you need to specify the actual table name without include the file extension.
e.g
DataSet sasDs = new DataSet(); String sasLibrary = @"D\SomeFolder\"; OleDbConnection connection= new OleDbConnection("Provider=sas.LocalProvider; Data Source=" + sasLibrary); connection.Open(); OleDbCommand cmd= connection.CreateCommand(); cmd.CommandType = CommandType.TableDirect; cmd.CommandText = "TableName"; //other option is to use the cmd.ExecuteReader(); OleDbDataAdapter da = new OleDbDataAdapter(cmd); da.Fill(sasDs); //sasDs should contain the DataTable loaded at this point. //you can filter the results using the DataTable.Select() connection.Close();
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.