Solved

ASP/ADO Excel Update

Posted on 2006-06-22
8
307 Views
Last Modified: 2008-03-03
Below is the ASP code I am using to read and display all of the information from my excel spreadsheet.  I am wanting to be able to update the information in a column, and the last 3 lines of my code (commented out) is the code that I am trying to update it with.  I get the following error when I try to update:

Type mismatch.
/excel/man_excel.asp, line 39

If anyone has a better way to do this, I am open to suggestions.  If only Access or SQL were options...... :)  Thanks in advance for the help.

<%
Const adOpenStatic = 3
Const adLockPessimistic = 2

Dim cnnExcel
Dim rstExcel
Dim I
Dim iCols

Set cnnExcel = Server.CreateObject("ADODB.Connection")
cnnExcel.Open "DBQ=" & Server.MapPath("ccr.xls") & ";" & _
      "DRIVER={Microsoft Excel Driver (*.xls)};"

Set rstExcel = Server.CreateObject("ADODB.Recordset")
rstExcel.Open "SELECT * FROM Overview;", cnnExcel, _
      adOpenStatic, adLockPessimistic

      Response.Write("Original Data")

      Response.Write("<TABLE><TR>")
      For X = 0 To rstExcel.Fields.Count - 1
         Response.Write("<TD>" & rstExcel.Fields.Item(X).Name & "</TD>")
      Next
      Response.Write("</TR>")
      rstExcel.MoveFirst

      While Not rstExcel.EOF
         Response.Write("<TR>")
         For X = 0 To rstExcel.Fields.Count - 1
            Response.write("<TD>" & rstExcel.Fields.Item(X).Value)
         Next
         rstExcel.MoveNext
         Response.Write("</TR>")
      Wend
      Response.Write("</TABLE>")

'rstExcel.MoveFirst
'rstExcel.Fields(1).Value="TEST INFORMATION"
'rstExcel.Update
%>
0
Comment
Question by:jayh99
  • 6
8 Comments
 
LVL 6

Expert Comment

by:inviser
ID: 16962837
Is rstExcel.Fields(1).Value a number only field?
0
 
LVL 1

Author Comment

by:jayh99
ID: 16962931
No, it is formatted as "General"
0
 
LVL 1

Author Comment

by:jayh99
ID: 16962982
No, it is formatted as "General"
0
 
LVL 1

Author Comment

by:jayh99
ID: 16962986
Sorry about the double post, refreshed my browser.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 25

Accepted Solution

by:
clockwatcher earned 50 total points
ID: 16966404
Switching the connection provider from Excel ODBC to Jet and the following works for me:

<%
Const adOpenStatic = 3
Const adLockPessimistic = 2

Dim cnnExcel
Dim rstExcel
Dim I
Dim iCols

Set cnnExcel = Server.CreateObject("ADODB.Connection")
cnnExcel.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source="  & Server.MapPath("ccr.xls") & ";" & _
           "Extended Properties=""Excel 8.0;HDR=Yes"""

Set rstExcel = Server.CreateObject("ADODB.Recordset")

rstExcel.Open "SELECT * FROM Overview;", cnnExcel, _
     adOpenStatic, adLockPessimistic

      Response.Write("Original Data")

      Response.Write("<TABLE><TR>")
      For X = 0 To rstExcel.Fields.Count - 1
         Response.Write("<TD>" & rstExcel.Fields.Item(X).Name & "</TD>")
      Next
      Response.Write("</TR>")
      rstExcel.MoveFirst

      While Not rstExcel.EOF
         Response.Write("<TR>")
         For X = 0 To rstExcel.Fields.Count - 1
            Response.write("<TD>" & rstExcel.Fields.Item(X).Value)
         Next
         rstExcel.MoveNext
         Response.Write("</TR>")
      Wend
      Response.Write("</TABLE>")

    rstExcel.MoveFirst
    rstExcel.Fields(1).Value="TEST INFORMATION"
    rstExcel.Update

    rstExcel.close
    set rstExcel = nothing

    cnnExcel.Close
    set cnnExcel = nothing

%>
0
 
LVL 1

Author Comment

by:jayh99
ID: 16968097
For some reason I can only post numbers to the spreadsheet.  I formatted teh cells at both "General" & "Text" and still can only post numbers.  Any recommendations?
0
 
LVL 1

Author Comment

by:jayh99
ID: 16968178
Actually, I found that I can write to a different sheet in my workbook, however the text only displays when I run the asp code above that reads/writes the table.  I open the spreadsheet, and there is no text in the fields.I also tried writing to the .Name rather than the .Value, but that didn't work either, it gave errors.
0
 
LVL 1

Author Comment

by:jayh99
ID: 16968216
I got it figured out.  Thanks a lot for the help.  The problem was I wasn't starting with column 0, and I was missing the table with the information.  It was showing up in a hidden field.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now