simple data readting question  
Author Message
JordonMusser





PostPosted: .NET Framework Data Access and Storage, simple data readting question Top

I have done some searching with no luck.. perhaps this is so simple I am the only one that doesnt get it!

I need to read data from a XLS file(spreadsheet). I have read about using excel to open the sheet, then reading it.. but I would like to just read the data with out opening excel. IE< i want to read A3 to A25 and save it to an array. I need no other manipulation other than simply reading several different columns and and saving them to an array, so I dont see a need to have my VBA open excel..

Any pointers here I am a total newb. Mechanical Engineer with a software project I want to do.

thanks!



.NET Development12  
 
 
ahmedilyas





PostPosted: .NET Framework Data Access and Storage, simple data readting question Top

easily done my friend.

the Statement would be:

"SELECT * FROM [SheetName$A3:A25]"

overall....

Dim theDataSet as new DataSet()

Dim theOleDbCommand as new OleDbCommand("SELECT * FROM [SheetName$A3:A25]", new OleDbConnection(ConnectionStringHere))

Dim theOleDbDataAdapter as new OleDbDataAdapter(theOleDbCommand)

theOleDbCommand.Connection.Open()

theOleDbDataAdapter.Fill(theDataSet)

theOleDbCommand.Connection.Close()

 

Me.theDataGridView.DataSource = theDataSet.Tables(0).DefaultView

 

www.connectionstrings.com -> for your connection strings

be sure to import the System.Data.OleDb namespace in your import declarations