Solved

ASP/ADO Excel Update

Posted on 2006-06-22
8
314 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:jayh99
ID: 16962986
Sorry about the double post, refreshed my browser.
0
 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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