Solved

ASP/ADO Excel Update

Posted on 2006-06-22
8
313 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
Independent Software Vendors: 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

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 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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

740 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