Solved

ASP/ADO Excel Update

Posted on 2006-06-22
8
315 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

630 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