Last post May 09, 2017 07:57 AM by jb2_86_uk
May 05, 2017 03:25 PM|jb2_86_uk|LINK
I have been hammering this forum for the last few days, but unfortunately I've not been able to find or work out a solution to my problem. I am very new to HTML/ASP/ADO/you name it! I have a good understanding of VB from writing macros in Excel
- but that's about it. However I am eager to learn!
I'm developing an asset tracking utility for my employer, and have come to the conclusion that I need to produce a webapp for data collection across the site. Using some great info from this site, I developed a simple UI page (default.asp) and a basic page
to write the user's inputs to a new record in my Access DB (demo_add.asp). It's nothing special, and I'm sure the code leaves a lot to be desired - but it worked... Until I deployed it to the webserver. I have unwittingly ran into the problem whereby ASP classic
is not compatible with IIS 7. I have successfully converted the default.asp into default.aspx, but I am stuck with the conversion/rewrite of demo_add.asp.
Can anyone suggest how this code should be amended to compile with ASP.NET? Any advice would be appreciated. The current compile error is from the line: "sql="INSERT INTO TrackQuery (WOPart,Activity,Status,Scrap_Reason)"" due to "sql" not being declared.
<%@ Page Language="VB" %>
Dim strConn as string = "Microsoft.ACE.OLEDB.12.0;Data Source=" _
& server.mappath("S:\Quality\Barcoding\Database\Tracker Database.accdb") & ";"
sql="INSERT INTO TrackQuery (WOPart,Activity,Status,Scrap_Reason)"
sql=sql & " VALUES "
sql=sql & "('" & Request.Form("WOPart") & "',"
sql=sql & "'" & Request.Form("Activity") & "',"
sql=sql & "'" & Request.Form("Status") & "',"
sql=sql & "'" & Request.Form("Scrap_Reason") & "')"
on error resume next
if err<>0 then
Response.Write("<h3>There has been a problem. Please contact your network administrator</h3>")
Response.Write("<a href=""default.aspx""><h3>Scan submitted, please click here to return to the previous page</h3></a>")
May 05, 2017 05:29 PM|PatriceSc|LINK
By default VB.NET requires a declaration for all variables (here Dim sql As String)
Depends the exact context. If this is a port from "classic ASP" you could use Option Explicit Off at the top of the file (and maybe plan later to turn that on again file by file later as declaring variable explicitely is best).
BTW classic ASP is not installed by default but AFAIK you have still support for that:
May 08, 2017 07:09 AM|Eric Du|LINK
According to your description and error message, you could use Dim to declare variable sql. please replace your code with the following code:
Dim sql As String
sql = "INSERT INTO TrackQuery (WOPart,Activity,Status,Scrap_Reason)"
sql = sql & Convert.ToString(" VALUES ")
sql = (sql & Convert.ToString("('")) + Request.Form("WOPart") + "',"
sql = (sql & Convert.ToString("'")) + Request.Form("Activity") + "',"
sql = (sql & Convert.ToString("'")) + Request.Form("Status") + "',"
sql = (sql & Convert.ToString("'")) + Request.Form("Scrap_Reason") + "')"
May 08, 2017 09:00 AM|jb2_86_uk|LINK
Thank you both, I had wrongly assumed the 'sql' was an action rather than a variable being called. Indeed, defining the variable has gotten me past that block of code - Thank you!
I think this is the last hurdle now, now when compiling it does not like the 'Execute' or 'Close' on the lines below - as they are "... not a member of 'String' ":
strConn.Execute sql, recaffected
Thank you for your help with this, I realise I am trying to run before I can walk, I just need to get this simple utility up and running before I can sit back and start with ASP.NET 101
May 09, 2017 07:57 AM|jb2_86_uk|LINK
Thanks all for the advice and tips, I was eventually able to work around these problems and successfully converted my ASP Classic code to ASP.NET.
Unfortunately the next problem is a network write-permissions issue for the Access DB, but that's another story!