Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP/ADO Excel Update

Posted on 2006-06-22
8
Medium Priority
?
316 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:jayh99
ID: 16962986
Sorry about the double post, refreshed my browser.
0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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 informatio…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

705 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