Print Page | Close Window

inserting data

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=22438
Printed Date: 29 March 2026 at 10:25am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: inserting data
Posted By: moseti
Subject: inserting data
Date Posted: 18 January 2007 at 12:59pm
Hi,
I have written code that inserts data into a database. Problem is that when the data is inserted, several blank records(2-3) are also inserted into the database. i pulled the tutorial off Web Wiz.

Can any body help
Confused



Replies:
Posted By: michael
Date Posted: 18 January 2007 at 2:22pm
Sure. You are doing something wrong Geek
 
No, but in all seriousness. We cannot really help without knowing what you are doing. Show us some code.


-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: moseti
Date Posted: 19 January 2007 at 11:57am

The code that that i am using is as follows


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/myConn.asp" -->
<%
Dim rsDetails
Dim rsDetails_numRows

Set rsDetails = Server.CreateObject("ADODB.Recordset")
rsDetails.ActiveConnection = MM_myConn_STRING
rsDetails.Source = "SELECT * FROM tblComments"
rsDetails.CursorType = 2
rsDetails.CursorLocation = 2
rsDetails.LockType = 3
rsDetails.Open()

rsDetails.Addnew
rsDetails.Fields("Name") = Request.Form("name")
rsDetails.Fields("Comments") = Request.Form("comments")
rsDetails.Update

<!--rsDetails_numRows = 0 -->
%>




Posted By: bootcom
Date Posted: 20 January 2007 at 12:05pm
Could you post the code from the form too please, I think I see whats going on here ... multiple form elements with the same name attribute


Posted By: Freon22
Date Posted: 22 January 2007 at 5:50pm
Not sure why you are doing a select statement. Anyways there are a few ways that you can insert into your database. When I was doing vbscript the first one I liked the best. I could run what I was inserting through a filter to make sure it was clean.
 
I am putting in the database connection so you make want to remove that part. I see you have an include file for you connection.
 

Dim objConn, strSQL
 
'Create the insert statement
strSQL = "INSERT INTO tblComments(Name, Comments) VALUES ('" & Request.Form("Name") & "', '" & Request.Form("Comments") & "')"
 
Set objConn = Server.CreateObject("ADODB.Connection")
 
objConn.ConnectionString= "Driver={Microsoft Access Driver(*.mdb)};" & _
"DBQ=" & Server.MapPath("db/yourdatabasename/mdb") 
 
'Open the connection
objConn.Open
 
'Execute the insert
objConn.Execute strSQL
 
'Close the database connection and set it to nothing
objConn.Close
Set objConn = Nothing
 
Another way is same as you are doing.

Dim objConn, objRS
 
Set objConn = Server.CreateObject("ADODB.Connection")
 
objConn.ConnectionString= "Driver={Microsoft Access Driver(*.mdb)};" & _
"DBQ=" & Server.MapPath("db/yourdatabasename/mdb") 
 
'Open the connection
objConn.Open
 
'Create a recordset
Set objRS = Server.CreateObject("ADODB.Recordset")
 
objRS.Open "tblComments", objConn, adOpenStatic, adLockOptimistic
 
'Add the new record to the database table
 
objRS.AddNew
 
objRS("Name") = Request.Form("Name")
objRS("Comments") = Request.Form("Comments")
 
objRS.Update
 
'Alway close your recordset and connection
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
Hope this helps


Posted By: MadDog
Date Posted: 23 January 2007 at 2:06am
Originally posted by moseti moseti wrote:


The code that that i am using is as follows


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/myConn.asp" -->
<%
Dim rsDetails
Dim rsDetails_numRows

Set rsDetails = Server.CreateObject("ADODB.Recordset")
rsDetails.ActiveConnection = MM_myConn_STRING
rsDetails.Source = "SELECT * FROM tblComments"
rsDetails.CursorType = 2
rsDetails.CursorLocation = 2
rsDetails.LockType = 3
rsDetails.Open()

rsDetails.Addnew
rsDetails.Fields("Name") = Request.Form("name")
rsDetails.Fields("Comments") = Request.Form("comments")
rsDetails.Update

<!--rsDetails_numRows = 0 -->
%>




Are you sure you got that tutorial from this website? Bruce (aka -boRg-) doesnt code like that (that is VERY dirty code!!!).


-------------
http://www.iportalx.net" rel="nofollow">


Posted By: moseti
Date Posted: 23 January 2007 at 1:01pm

Sorry, I have been away for some time. U asked for the form i have been using. The Code is as follows.

'Code for form

<form id="form1" name="form1" method="post" action="add_to_guestbook II.asp">
Name: 
  <input type="text" name="name" maxlength="20">
<br />
Comments: <input type="text" name="comments" maxlength="50">
     <input type="submit" name="Submit" value="Submit">
</form>

'tis but a simple form. As u can see from the previous code I had submitted, I am using - Request.Form("name") to read values from the name textbox.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net