BookmarkSubscribeRSS Feed
koolprasad2003
Calcite | Level 5

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

4 REPLIES 4
ottomano
Calcite | Level 5

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

Ksharp
Super User

@"D\a.sas7bdat";

->

@"D:\a.sas7bdat";   ?

richardlalonde
Calcite | Level 5
Thx very much - finally !
robmx
Calcite | Level 5

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();

  

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 6707 views
  • 2 likes
  • 5 in conversation