ordering on importing dataset from EXCEL!!!

Wirloff

Member
Joined
Mar 2, 2005
Messages
19
Location
Belgium
Programming Experience
1-3
Hi,

I know that when you fill a dataset with data from a database you can use the names of the columns of the tabel in the database to sort on..

ex:
Dim
oConn As OleDbConnection
Dim OCmdItem As OleDbCommand
Dim dsItem As DataSet
Dim daItem As OleDbDataAdapter
Dim strSQL As "select ... from .... ORDER BY (!!!!!)columnName)...."
oCmd = new oledbcommand(strSQl, oConn)
daItem = new oledbdataadapter
daItem.selectCommand = oCmdItem
daItem.fill(dsItem)


But now my question comes, is it also possible to do this while importing from an excel file..
I have managed to import a dataset from an excel file, but it's just "select * from [excelfile] "
It should be ordered before I start to work with the data in the dataset..

=> Is this possible?

=> Is there an other way?

Please help
 

ritesh_jain1982

Well-known member
Joined
Jan 10, 2005
Messages
53
Programming Experience
1-3
Hi,
why don't u use dtTable.DefaultView.Sort property to sort ur Datatable and work with defaultview of the Datatable.

I hope this will help u...............

Regards,
Ritesh
 

bloukewer

Well-known member
Joined
Jul 2, 2004
Messages
88
Programming Experience
3-5
You can also specify the rows and columns by their respective row-or-column numbers. This works for databases, and since spreadsheets are also just two-dimensional arrays... it just might work.
 

Jacks

New member
Joined
Apr 8, 2005
Messages
4
Programming Experience
1-3
ordering on importing dataset from EXCEL???????

Hi,

Could you post the code for Importing Excel data into a vb.net dataset.
Can't seem to fig this one out.

Thanks

Jacks
 

ritesh_jain1982

Well-known member
Joined
Jan 10, 2005
Messages
53
Programming Experience
1-3
Hi,

u can read the Records from ex sheet as ...........
Dim exlApp As New Excel.Application()
Dim exlBook As Excel.Workbook = exlApp.Workbooks.Open(tbFileName.Text.Trim)

Dim exlSheet As Excel.Worksheet = exlBook.Worksheets.Item(tbWorkBook.Text.Trim)

for intCounter = 1 to TotalRows

strFirstColValue= exlSheet.Cells.Range("A1" & intCounter).Value
'after reading values u can insert these into Datatable using New dataRow....\
next


I hope this will help u..............

Regards,
Ritesh
 
Top Bottom