Wrox Programmer Forums
|
Access ASP Using ASP with Microsoft Access databases. For Access questions not specific to ASP, please use the Access forum. For more ASP forums, please see the ASP forum category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access ASP 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 July 28th, 2005, 12:50 AM
Authorized User
 
Join Date: Jul 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inserting data into Sqlserver

Hi,
can any one help me out for inserting data into SQL SERVER From asp page using stored procedure.
I am having a text boxes in my ASP PAGE,
If i enter data in the textboxes it should be inserted into the table in SQL SERVER.


Thanks in Advance,
Ram.

 
Old July 28th, 2005, 03:23 PM
Authorized User
 
Join Date: Mar 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to arimakidd
Default

Hi Ram
See if the following code helps. Just remember because you are using SQL instead of Access as a datastore the dsn-less connection line will change. And Instead of stating the SQL Statement you would just put your "procedure". I am assuming alot by just giving you this code and I hope you understand it. Just remember use your procedure instead of the SQL commands and you will change the line for the dsn-less connection, don't have it on me right now but if you need it let me know and i'll post it. Here goes:
Code:
<%
'Dimension variables
Dim adoCon              'Holds the Database Connection Object
Dim rsAddComments   'Holds the recordset for the new record to be added
Dim strSQL               'Holds the SQL query to query the database

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("guestbook.mdb")

'Set an active connection to the Connection object using DSN connection
'adoCon.Open "DSN=guestbook"

'Create an ADO recordset object
Set rsAddComments = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT tblComments.Name, tblComments.Comments FROM tblComments;"

'Set the cursor type we are using so we can navigate through the recordset
rsAddComments.CursorType = 2
'Set the lock type so that the record is locked by ADO when it is updated
rsAddComments.LockType = 3
'Open the recordset with the SQL query
rsAddComments.Open strSQL, adoCon
'Tell the recordset we are adding a new record to it
rsAddComments.AddNew
'Add a new record to the recordset
rsAddComments.Fields("Name") = Request.Form("name")
rsAddComments.Fields("Comments") = Request.Form("comments")
'Write the updated recordset to the database
rsAddComments.Update
'Reset server objects
rsAddComments.Close
Set rsAddComments = Nothing
Set adoCon = Nothing
'Redirect to whatever page you want
Response.Redirect "newpage.asp"
%>






Similar Threads
Thread Thread Starter Forum Replies Last Post
SQLserver 2000 vs SQLserver 2005 Express cJeffreywang BOOK: Beginning ASP.NET 2.0 and Databases 0 April 22nd, 2007 09:52 AM
Inserting picture into Sqlserver using JSp Thushara Jacob Pulickal Pro JSP 0 May 4th, 2006 12:42 AM
Displaying SQLServer data to user sss22 ASP.NET 1.0 and 1.1 Basics 1 October 28th, 2005 01:05 PM
How to write xml data in SqlServer rekha_jsr XML 1 October 21st, 2004 12:22 PM
casting textbox to sqlserver number data type yoord BOOK: Beginning ASP.NET 1.0 1 October 17th, 2004 06:09 AM





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