Database Code
  Home arrow Database Code arrow Write records to a SQL 7.0 database, retur...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE CODE

Write records to a SQL 7.0 database, return the unique id # ( Working Demo try it out!)
By: aspfree
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 3
    1999-09-01

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    ASP, MS-SQL Server & Stored Procedures to Add records & return data to an ASP page Without using the Command Object!!!

              

    This example is for those looking to write records from an asp page to Microsoft SQL Server 6.5 or 7.0 database using a stored procedure without trying to use the command object like in Microsoft's examples.  I could never get those to work!   So I invented my own.  I'm probably not the 1st to use this method but I was happy I discovered it!  This example  also after writing the records to the database,  information can be retrieved (i.e an Identity column #) and write data back to the asp page & your end user.    Sorry this demo is a lot more babble than any other demo's but the concept here is a bit more involved.

    Most of the examples I found on the net all relate to writing from
    ASP to Access97 databases.  This is all fine when the app is departmental

    in nature or just using the Access db to extract pre-existing information to be
    written to the asp page.  If your web application is doing inserts, updates or
    deletes and have a fair amount of users, use a MS SQL Server database.   Any kind
    of size to the audience using the web app and I strongly recommend
    Microsoft SQL Server as the back-end database. 

    Another nice feature in using SQL Server is then the owners of the data can easily
    access live data through an Access 97 database via an ODBC driver.  You can build
    your front end for the end user of the data using Access 97.  I have found most
    people like using Access as a front end tool that does Querying/Reporting.  In my
    opinion that is why Access is the perfect front-end tool. (And NO Microsoft didn't
    pay me to say that!!! Wish they did though!!):)) 

    Please take sometime to review this free code, I have invested a great deal of time
    searching the Net for information on Active Server Pages.    I always believe you get
    10 times or more back of what you give.  Please take sometime and Click here to download the SQL Server scripts to create the tables in this example.
    d.  You have created some input form and a asp page to do the processing.   The below
         example show two WebPages(1: An input form, 2: Processformdata.asp that contains
         all the asp code. 

    PAGE ONE INPUT FORM: (SomeInputform.html)

    1.  the user will input some information and click submit to
         an Active server page. This example we will input a firstname
         and a last name.    Then click submit

    PAGE TWO ASP PAGE CODE: (processformdata.asp)

    <%
    'Declare variables
    dim strconn
    dim conn
    dim rs
    dim strsql

    dim strsql2
    dim strsql3

    dim recordIDvalue


    'This formats the data from the Input form and will be passed into the database.
    'At the end of the formatted string is how I return the value
    'This easily could be Select * from TableName to return the whole recordset

    strsql1 = "Declare @req_num int Exec spName"
    strsql2 = "'" & request.form("txtfield1") & "'," & "'" & request.form("txtField2") "'," &   @req_num OUTPUT
    strsql3 = "select table1.recordid from table1 where recordid = @req_num"
    strsql = strsql1 & strsql2 & strsql3

    'In this example the formatted string will look like this. A good way to test
    'for this is to do a response.write out  your code that will be executed on the asp page
    'Copy and Paste in the query window of SQL server 6.5 or 7.0.  This will help you determine if your syntax is right.  Formatted SQL is a bit fussy.
    declare @req_num int EXEC spName 'John','Doe', @REQ_NUM OUTPUT SELECT @@Identity

    'Set your connection & recordset objects
    set conn = server.createobject("adodb.connection")
    conn.open "dsnname or connectionstring"
    set rs = server.createobject("adodb.recordset")
    rs = conn.execute(strsql)

    'Set a local variable that will be used to write out the value
    recordIDvalue = rs("Identity_Value_That_was_Created_When_Inserted")
    conn.close
    Set rs = nothing
    set conn = nothing
    %>
    <
    html
    >
    <
    head
    >
    <
    title>Asp page that will do the processing</title
    >
    <
    /head>
    <body
    >
    <
    p>Your record number is:<% = recordIDvalue  %> </p
    >
    <
    /body
    >
    <
    /html>

     


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Database Code Articles
    More By aspfree

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Evaluate IBM Lotus Sametime Standard V8.0

    Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration.
    FREE! Go There Now!


    NEW! Maintaining QoS and Process Integrity in an SOA Environment

    This webcast outlines the best practices that must be instituted to gain the maximum benefit from SOA while maintaining high quality of service. Whether you are deploying new applications or managing and monitoring your existing infrastructure, learn how you can ensure high quality of services with SOA based solutions from IBM. All registrants who attend this live Web Seminar will receive complimentary access to a white paper titled “Maintaining QoS in an SOA Environment”.
    FREE! Go There Now!


    NEW! Rational 'Talks to You' Teleconference Series

    This Fall, IBM Rational talks to you directly through a special teleconference series giving you access to the best minds in IBM Rational - product experts and market thought leaders who will answer your questions during these pre-scheduled telephone conference calls. Register today!
    FREE! Go There Now!


    NEW! Rational Talks to You: Manage RUP-based CMMI initiatives

    Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered!
    FREE! Go There Now!


    NEW! Rational Talks to You: Scott Ambler on being agile in a global development environment

    Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered!
    FREE! Go There Now!


    NEW! Trial download: IBM Informix Dynamic Server Express Edition V11.0

    Informix Dynamic Server (IDS) Express Edition offers outstanding online transaction processing (OLTP) database performance, while helping to simplify and automate many of the tasks associated with deploying databases for small business applications. IDS 11 further extends the ease of management and applications integration with the Admin API and Scheduler, high availability with Continuous Log Restore for backup server recovery in case of a primary server failure, and column level encryption to protect personal and company private data.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for People

    Visit IBM developerWorks to try the IBM SOA Sandbox for people. The SOA Sandbox for people provides a trial environment with the necessary tooling and components required to enable consistent human and process interaction and collaboration, showing how you can improve user experience and business productivity.
    FREE! Go There Now!


    NEW! Webcast: Extreme transaction processing with WebSphere Extended Deployment

    In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications.
    FREE! Go There Now!


    NEW! Webcast: Quickly provide customized, integrated user interfaces with Lotus Notes 8

    IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community.
    FREE! Go There Now!


    NEW! Webcast: WebSphere Process Server

    WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    DATABASE CODE ARTICLES

    - Deployment of the MobiLink Synchronization M...
    - MobiLink Synchronization Wizard in SQL Anywh...
    - Finding Matching Records in Data Access Pages
    - Using the AccessDataSource Control in VS 2005
    - A Closer Look at ADO.NET: The Command Object
    - A Closer Look at ADO.NET: The Connection Obj...
    - Using ADO to Communicate with the Database, ...
    - Code Snippets: Counting Records
    - Constraints In Microsoft SQL Server 2000
    - Multilingual entries into a DB and to be dis...
    - Getting A List of Tables From SQL Server
    - SQL Server Database Creator - .NET Version
    - ADO Recordset Paging
    - Two combos, one textbox example
    - Discussion & Listserv Module by Mike Eck...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek