kstoneman10
Member
- Joined
- Feb 20, 2010
- Messages
- 11
- Programming Experience
- 3-5
I've been giving the following code to search an Excel file for specific data. Currently, this code looks for a date within the worksheet.
My questions are:
1. Why is the "$" needed for sheet name?
2. Why is "F" used in the SQL string?
3. Right now it finds the date in row 3 of the worksheet. How can I search for data in another row?
Any assistance is greatly appreciated.
Kevin
My questions are:
1. Why is the "$" needed for sheet name?
2. Why is "F" used in the SQL string?
3. Right now it finds the date in row 3 of the worksheet. How can I search for data in another row?
VB.NET:
Imports Microsoft.Office.Interop
Imports System.Data.OleDb
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ExcelCon As OleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\test2.xlsx;Extended Properties=""Excel 12.0;HDR=No"";")
Dim str1 As String
Dim rs1 As OleDbDataReader
Dim col As Integer
For i = 4 To 200 Step 6
ExcelCon.Open()
str1 = "SELECT * " & _
"FROM [2011_Rollup_2Hx$] " & _
"Where F" & i & " ='9-Jul-11' "
MsgBox(str1)
Dim sql1 As OleDbCommand = New OleDbCommand(str1, ExcelCon)
rs1 = sql1.ExecuteReader
rs1.Read()
If rs1.HasRows = True Then
col = i
i = 200
End If
MsgBox("found")
ExcelCon.Close()
Next
End Sub
End Class
Any assistance is greatly appreciated.
Kevin