reading excel file in vb.net
Posted
by Mark
on Stack Overflow
See other posts from Stack Overflow
or by Mark
Published on 2010-04-17T10:00:34Z
Indexed on
2010/04/17
10:53 UTC
Read the original article
Hit count: 267
can anyone help me on how to know EOF of excel using vb.net?
i have this code but it crash when i try delete the proceeding rows from row 6 to downward.
my problem is, my code was still reading a null values of rows that i deleted in excel..
this is my code:
Dim xlsConn As New OleDbConnection
Dim xlsAdapter As New OleDbDataAdapter
Dim xlsDataSet As New DataSet
xlsConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & pathName & " ; Extended Properties=Excel 8.0")
strSQL = "SELECT * FROM [Sheet1$]"
xlsAdapter.SelectCommand = New OleDbCommand(strSQL, xlsConn)
xlsDataSet.Clear()
xlsAdapter.Fill(xlsDataSet)
ListView1.Items.Clear()
Dim listItem As ListViewItem
For ctr As Integer = 0 To xlsDataSet.Tables(0).Rows.Count - 1
listItem = ListView1.Items.Add(xlsDataSet.Tables(0).Rows(ctr).Item("EmpNo").ToString)
listItem.SubItems.Add(xlsDataSet.Tables(0).Rows(ctr).Item("EmpName").ToString)
Next
Can anyone help me to fix this bugs!
© Stack Overflow or respective owner