'## Create Connection and Recordsets Dim Conn, RS Set Conn = CreateObject("ADODB.Connection") Set RS = CreateObject("ADODB.Recordset")Next, lets create a variable for the file name. In this example, let's say we named the file "EventData.xls".
'## The Excel File Name XLFile = "F:\webdata\EventData.xls"Now, we have to define what data we want to get. Most of the time, we'll want all the data. This case is no exception, so we create a SQL query to get everything from the data we defined as "Events".
'## The Data to extract szSQL = "select * from Events"To get the data, we need to open the connection to the data source. Here is where we stick in the name of the file defined above. You could just as easily put the file in this line, as well.
'## Create and open the connection Conn.ConnectionString = "DBQ=" & XLFile & ";DRIVER=Microsoft Excel Driver (*.xls);UID=admin;" Conn.OpenOnce this is done, we set some properties on the recordset and use the Recordset.Open method to get the specific data from our spreadsheet. By default, ADO creates Forward Only recordsets. We'll make ours static. After we get the data, we can disconnect the Active connection, since we don't need it anymore.
'## set the cursor to be static. rs.cursortype = 3 ' adStatic.Now we can operate on the data just like any other recorddata. Here, we will iterate through the data, displaying the events on the web. Naturally, we could generate any formatting we want.'## open the recordset
rs.open szSQL, conn'## Disconnect recordset, eliminate connection
rs.activeconnection = nothing Conn.Close Set Conn=nothing
'## iterate through the recordset.while not rs.eof response.write RS("name") & " -- " response.write RS("location") & " -- " response.write RS("Coordinator") & " -- " response.write RS("Date") & " -- " response.write RS("Time") & "<BR>" rs.movenextwendFinally, we close out the recordset and release it. Of couse, you could skip this set and move the data into the user's session, if they were going to be querying it repeatedly. For now, we'll assume that isn't the case.
RS.closeSet RS=nothingThis should get you started. Of course there are all kinds of neat things you can do once your data is imported into an ADO Recordset. Excellent information is available from the Able Consulting's Technology Page.