| Author |
Topic Search Topic Options
|
moseti
Newbie
Joined: 18 January 2007
Location: Kenya
Status: Offline
Points: 3
|
Post Options
Thanks(0)
Quote Reply
Topic: inserting data 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
|
 |
michael
Senior Member
Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
|
Post Options
Thanks(0)
Quote Reply
Posted: 18 January 2007 at 2:22pm |
Sure. You are doing something wrong
No, but in all seriousness. We cannot really help without knowing what you are doing. Show us some code.
|
|
|
 |
moseti
Newbie
Joined: 18 January 2007
Location: Kenya
Status: Offline
Points: 3
|
Post Options
Thanks(0)
Quote Reply
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 --> %>
|
 |
bootcom
Senior Member
Joined: 26 February 2005
Location: United Kingdom
Status: Offline
Points: 259
|
Post Options
Thanks(0)
Quote Reply
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
|
 |
Freon22
Groupie
Joined: 04 December 2005
Status: Offline
Points: 42
|
Post Options
Thanks(0)
Quote Reply
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
|
 |
MadDog
Mod Builder Group
Joined: 01 January 2002
Status: Offline
Points: 3008
|
Post Options
Thanks(0)
Quote Reply
Posted: 23 January 2007 at 2:06am |
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!!!).
|
|
|
 |
moseti
Newbie
Joined: 18 January 2007
Location: Kenya
Status: Offline
Points: 3
|
Post Options
Thanks(0)
Quote Reply
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.
|
 |