Using Excel 2016 as database in ASP Classic - asp-classic

Does anyone know how I can display the content of an Excel 2016 file in a webpage?
I cannot figure out how to open a connection from the webpage nor which drivers I might need to install in order to open the ODBC or DSN connection.
Can anyone help me?

I got it working after using a couple of hours on it.
Heres how I read the data out
<%
Dim Conn, Sql, rs
Set Conn = Server.createobject("ADODB.Connection")
Conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\inetpub\wwwroot\test\test.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=1"";"
' Ark1 is danish for Sheet1
Sql = "select * from [Ark1$]"
set rs = Conn.Execute(Sql)
do while not rs.eof or rs.bof
response.write rs("test") & "<br>" & vbCrLf
rs.movenext
loop
Conn.CLose
Set Conn = nothing
%>
Hope this might help others.

Related

Type Mismatch error in ADODB.Connection code

I have made a code to send data from excel to access as its a repetitive task in my office. I do not know VBA, i have copied this code from internet and have made modifications whereever required. However, its throwing Run Time Error 13 Type Mis Match Error. I am very upset with this error, please see if you guys can help. Thanks in advance. Code is below:
Private Sub CommandButton1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
'set up connection string
cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\anurag85678\Desktop\Tracker\Database2.accdb;Persist Security Info=False;"
'connect to database
cn.Open
Set rs = New ADODB.Recordset
rs.Open "Test", cn, adOpenKeyset, adLockOptimistic, adCmdTable
With rs
.AddNew
.Fields("ID") = Sheets("Sheet1").Range("A1")
.Fields("Name") = Sheets("Sheet1").Range("B1")
.Fields("Process_Name") = Sheets("Sheet1").Range("C1")
.Fields("Companies_Done") = Sheets("Sheet1").Range("D1")
.Update
End With
' Close the recordset and connection
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
Best Regards,
Anurag

insert data into ms access, using asp

im trying to insert a new row with new data to an ms access table, using asp page.
i have no background in asp, im an android developer, but those are my client specifications.
i know im doing something very wrong, but i dont know what...
can you please help me?
this is what i was trying to do:
<%
'define variables
dim conn, strsql, strMDBPath
Set conn = Server.CreateObject("ADODB.Connection")
'Connect to the database
strMDBpath = Server.MapPath("data.mdb")
conn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & strMDBPath
'On Error Resume Next
'write to the database
strSql = "INSERT INTO avi (id,first,last) VALUES ("4", '" yom "','" cobi "')"
conn.Execute(strSql)
'close database
conn.close
Set conn = nothing
%>
You're missing some ampersands.
strSql = "INSERT INTO avi (id,first,last) VALUES (4, '" & yom & "', '" & cobi & "')"

Save ASP classic form into a specific column in excel

I'd to know if it's possible to have my asp classic form saved into a excel file in a column after submit?
Thank you all.
use the Microsoft.Jet.OLEDB Driver to access the excel sheet like so:
dim conn : set conn = server.createObject("ADODB.Connection")
dim rs : set rs = server.createObject("adodb.recordset")
dim sql
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &_
"myExcelFile.xls;" &_
"Extended Properties=""Excel 8.0;HDR=YES;"""
then you yould use just sql to insert your data...
the possible connectionstrings for excel are listed here
THE BELOW CODE IS TO INSERT INTO AN EXISTING EXCEL FILE. THIS IS WHAT YOU NEED.
<%
Option Explicit
' OPEN DATABASE
dim objConn,strConnection,objRS,strQuery
'Set objConn = New ADODB.Connection
set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("TEST.xls") & "; Extended Properties=Excel 8.0;"
objConn.Open strConnection
'Set objRS = New ADODB.Recordset
set objRS = Server.CreateObject("ADODB.Recordset")
set objRS.ActiveConnection = objConn
' This is to Select A1:A1 and open the recordset
strQuery = "SELECT * FROM A1:A1"
objRS.Open strQuery
' This is to insert into A1:A1 a value that says: testttest
strQuery = "insert into [A1:A1] values('testttest')"
' Close and destroy the Connection object.
objConn.Execute strQuery
objConn.Close
Set objRS=Nothing
Set objConn=Nothing
%>
TO UPDATE A SPECIFIC COLUMN
You can do this: See here: http://bytes.com/topic/asp-classic/answers/620074-update-existing-excel-file-using-asp-urgent
and also here: Update Excel Sheet (in Classic ASP/Vbscript)

Update Excel Sheet (in Classic ASP/Vbscript)

I tried to search for a code that would update a Excel (XLS) file in Classic-ASP but I cannot get it to work.
here is what I have:
<!--#include file="../adovbs.inc"-->
<%
' Open and Update and then Close The XLS File
Dim objConn
set objConn = Server.CreateObject("ADODB.Connection")
Dim FLConnect
Dim strSQLexcel
' Create the connection string.
FLConnect = "Provider=Microsoft.Jet.OLEDB.4.0 Data Source=" & Server.MapPath("TEST.xls") & "Extended Properties='Excel 8.0;HDR=No'"
' Create the SQL statement.
strSQLexcel= "UPDATE [Sheet1$A1:A1] SET F1='TestValue1'"
set objConn = Server.CreateObject("ADODB.Recordset")
'Set objConn = New ADODB.Connection
' Create and open the Connection object.
objConn.Open FLConnect
' Execute the insert statement.
objConn.Execute strSQLexcel
' Close and destroy the Connection object.
objConn.Close
%>
But I keep getting an error saying: " The connection cannot be used to perform this operation. It is either closed or invalid in this context. "
Thank you so much...
Your connection string is not right.
You have:
Provider=Microsoft.Jet.OLEDB.4.0 Data Source="
& Server.MapPath("TEST.xls") & "Extended Properties='Excel 8.0;HDR=No'"
You are missing a semi-colon after 4.0 and before Extended
Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
& Server.MapPath("TEST.xls") & ";Extended Properties='Excel 8.0;HDR=No'"
See http://connectionstrings.com
This connection string worked best for me:-
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myExcel.xlsm;Extended Properties='Excel 12.0 Macro;HDR=YES';

How to read CSV files line by line in VBScript

I am using an ASP page where I have to read a CSV file and insert it into DB table "Employee". I am creating an object of TestReader. How can I write a loop to execute up to the number of rows/records of the CSV file which is being read?
Do not try to parse the file yourself, you'll just give yourself a headache. There's quite a bit more to it than splitting on newline and commas.
You can use OLEDB to open up the file in a recordset and read it just as you would a db table. Something like this:
Dim strConn, conn, rs
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("path to folder") & ";Extended Properties='text;HDR=Yes;FMT-Delimited';"
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open strConn
Set rs = Server.CreateObject("ADODB.recordset")
rs.open "SELECT * FROM myfile.csv", conn
while not rs.eof
...
rs.movenext
wend
My vbscript is rusty, so verify the syntax.
edit: harpo's comment brings up a good point about field definitions. Defining a schema.ini file allows you to define the number and datatypes of the expected fields. See: You can handle this by defining a schema.ini file. see: http://msdn.microsoft.com/en-us/library/ms709353.aspx
Why not just insert the CSV? For example:
SELECT * INTO MyTable FROM OPENDATASOURCE('Microsoft.JET.OLEDB.4.0',
'Data Source=F:\MyDirectory;Extended Properties="text;HDR=No"')...
[MyCsvFile#csv]
From: http://coding.derkeiler.com/Archive/Delphi/borland.public.delphi.database.ado/2007-05/msg00057.html

Resources