Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 19th, 2012, 10:51 PM
Authorized User
 
Join Date: Aug 2011
Posts: 34
Thanks: 1
Thanked 1 Time in 1 Post
Default Form to either Update or Insert data in SQL table

I have a report that generates a list of servers, local User accts and a Custom Label. I have a form that will allow a user to manually put in the information but there is also a service that could add the Server Name and Local user acct.

So I need my form to first see if the server name and local user acct exist, if it does, then update the column Custom Label. Else I need too insert the Server Name, Local user acct and Custom Label.

Code:
<%@ Language=VBScript %>
<% Option Explicit %>
<!-- #include file = "conn.asp" -->
<!--#include virtual="adovbs.inc"-->
<%  DIM strServer,cpSearch,strUserlbl,strUserID,User_ID
strServer = Request.Form("servername")
strUserID = Request.Form("userid")
strUserlbl = Request.Form("useracctlbl")
%>
<% 
  Dim objRS,objConn,testSQL,objRS2, mySQL
  Set objConn = Server.CreateObject("ADODB.Connection")
  objConn.ConnectionString = sConnection
  objConn.Open
  testSQL = "select count(*) AS Userlbl from LocalUserLabel where server_name =  '" & strServer & "'" and User_ID =  "'" & strUserID & "'"
if Userlbl = 0 then
  Set objRS = Server.CreateObject("ADODB.Recordset")
  objRS.Open "LocalUserLabel", objConn, adOpenStatic, adLockOptimistic, adCmdTable
  objRS.AddNew Array("Server_Name", "User_ID", "CustomLabel"), Array(uCase(Request.Form ("servername")), Request.Form("userid"), uCase(Request.Form("useracctlbl")))
  objRS.Update
 end if
if Userlbl = 1 then
mySQL = "SELECT * FROM server WHERE server_name = '" & strServer & "'"
       Set objRS2 = Server.CreateObject("ADODB.Recordset")
       objRS2.Open mySQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText
objRS2("CustomLabel") = Request.Form("useracctlbl")
  objRS2.Update
  end if
  objRS.Close
  Set objRS = Nothing
  objRS2.Close
  Set objRS2 = Nothing
  objConn.Close
  Set objConn = Nothing
  Response.Redirect "customerLabelrpt.asp"
%>
I get an error:

Type mismatch: '[string: "select count(*) AS U"]'

Can I please get some assistance on creating my page. Let me know if any other information is needed.

Thanks,
 
Old September 20th, 2012, 07:01 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

You should indicate the line number point out which line this is in your code. help others help you!!

You are lucky I can tell from the msge what line it is. you have got all double quote happy with your SQL. This is what you need to have:

Code:
testSQL = "select count(*) AS Userlbl from LocalUserLabel where server_name =  '" & strServer & "' and User_ID = '" & strUserID & "';"
Note - The trailing semi colon is not required and is not part of the solution but a good idea for a few reasons. you should alays place a semi colon at the end of every SQL statement
__________________
Wind is your friend
Matt
 
Old September 20th, 2012, 08:23 PM
Authorized User
 
Join Date: Aug 2011
Posts: 34
Thanks: 1
Thanked 1 Time in 1 Post
Default

Hello Matt,

Thank you for your assistance. I was able to proceed but unfortunately I got a different error:

Microsoft VBScript runtime error '800a01a8'

Object required: ''

/servermgmtfsa/customerLabelrpt_update2.asp, line 31


Line 31 references line objRS2.Close.

Not sure why this would be a problem, when I took out the two references about objRS2, Line 31 & 32, the process would complete but nothing was updated or inserted.

Any additional information/help would be greatly appreciated.

Thanks,





Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Data in SQL 2005 table bex ASP.NET 3.5 Basics 9 July 10th, 2009 06:18 AM
Trigger : after update insert into second table ik SQL Server 2000 4 January 30th, 2009 12:32 AM
insert form data in an sql and email the content ddnk77872 PHP Databases 3 February 13th, 2007 09:47 AM
Update table using SQL query from form pater53 Access VBA 4 January 24th, 2007 11:24 AM
Update SQL table with data from FoxPro system sofya SQL Server 2000 6 November 4th, 2004 06:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.