Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. 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 Databases 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 February 12th, 2004, 06:01 AM
Authorized User
 
Join Date: Feb 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help Please with my code to insert data

Hi, I have been trying to figure out what's wrong with my coding, but i could not figure out why i cant insert my data to the table? i have 2 form which first form for insert data and after submit button the viewdata form will be show. i have a lot of fields in my table, so i will only show 9 column. the database i'm using is Access, and for the connection DSN.in my table i'm using 2 fileds of Number,
one with auto number the other with number i dont know this have affect or not.

these are my code for first form
<! --#include file="Source.asp" -->
<%
Dim intAngka,intNomer, varEmployeeNo, varSurname, varGivenName
Dim varStatus, varSection, varAddress, varHired_date
Dim strConnect, rsData, Conn, strSQl

intAngka = Request.Form ("Angka") --the data type is auto number in access
intNomer = Request.Form ("Nomer") -- the data type is number in access
varEmployeeNo = Request.Form ("EmployeeNo")
varSurname = Request.Form ("Surname")
varGivenName = Request.Form ("GivenName")
varStatus = Request.Form ("Status")
varSection = Request.Form ("Section")
varAddress = Request.Form ("Address")
Hired_date = Request.Form ("DateofHired")

Session ("Angka") = intAngka
Session ("Nomer") = intNomer
Session ("EmployeeNo") = varEmployeeNo
Session ("Surname") = varSurname
Session ("GivenName") = varGivenName
Session ("Status")= varStatus
Session ("Section") = varSection
Session ("Address") = varAddress
Session ("DateofHired") = Hired_date

If Request.Form("submit1")= "submit1" Then
Set Conn = Server.CreateObject ("ADODB.Connection")
Conn.Open "DSN=Insert"

strsql ="INSERT INTO Expat_EmployeeReg " &_
"(Nomer,Surname,GivenName,Status,EmployeeNo " & _
"Section,DateofHired,Address)" & _
"VALUES (" &_
"'"&intNomer&"','" & varSurname & "','" & varGivenName & "','" & varStatus & "','" & varEmployeeNo & "', " & _
"'" & varSection & "', '" & Hired_date & "','" & varAddress & "')"
Conn.Execute strSql

If Conn.State then
   Conn.Close
set Conn= Nothing
end if
%>

code for my second form:
<%
Dim intAngka,intNomer, varEmployeeNo, varSurname, varGivenName
Dim varStatus, varSection, varAddress, varHired_date
Dim strConnect, rsData, Conn, strSQl, i, lngRecordNo

lngRecordNo = (Request.QueryString("Nomer"))
intAngka = Session("Angka")
intNomer = Session("Nomer")
varEmployeeNo = Session ("EmployeeNo")
varSurname = Session ("Surname")
varGivenName = Session ("GivenName")
varStatus = Session ("Status")
varSection = Session ("Section")
varAddress = Session ("Address")
Hired_date = Session ("DateofHired")

Set Conn = Server.CreateObject ("ADODB.Connection")
Conn.Open "DSN=Insert"
Set rsData = Server.CreateObject ("ADODB.Recordset")
strSQL= "SELECT * FROM Expat_EmployeeReg"
rsData.Open strSQl, Conn
i=1
%>
<%
Do While Not rsData.EOF
%>
<TD><%=i%></TD>
 <TD><%=rsData("Nomer")%></TD>
 <TD><%=rsData("EmployeeNo")%></TD>
 <TD><%=rsData("Surname")%></TD>
 <TD><%=rsData("GivenName")%></TD>
 <TD><%=rsData("Status")%></TD>
 <TD><%=rsData("Section")%></TD>
 <TD><%=rsData("Address")%></TD>
<TD><%=rsData("DateofHired")%></TD>
<%
i = i + 1
rsData.MoveNext
Loop
rsData.Close
Conn.Close
Set rsData= Nothing
Set Conn= Nothing
%>
maybe someone can help me with the coding i really Appreciate,
thank you
 
Old February 12th, 2004, 06:26 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

Can youi print the SQL String before you execute it and then try running that in Query Analyser to see if that reports an error.
 
Old February 12th, 2004, 06:33 PM
Authorized User
 
Join Date: Dec 2003
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Q1. Is there currently data in the table?

q2. If so, does your second form connect with and display that data.

John

 
Old February 12th, 2004, 10:32 PM
Authorized User
 
Join Date: Feb 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for your replay...Could you tell me how to do the query analyser, because i never use it.
yes in my table there is a current data and in my second form is connect and can display the current data where i entry the data from access. but when i run my code to insert data from web that's the problem...
 
Old February 13th, 2004, 12:25 PM
Authorized User
 
Join Date: Dec 2003
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Default

IT MAY BE A SYNTAX ISSUE WITH ALL THE APOSROPHES, QUOTES, ETC.

TRY REMOVING ALL INSERT FIELDS AND VALUES EXCEPT FOR ONE

IN OTHER WORDS, ONLY INSERT ONE VALUE INTO ONE FIELD,

THEN ADD A COUPLE MORE AND TEST, AND A COUPLE MORE AND TEST.

TEDIOUS, I KNOW BUT IT IS AN EFFECTIVE WAY TO TROUBLESHOOT.

THE FIRST ATTEMPT WILL CONFIRM PROPER CONNECTION WITH THE DB AND THAT YOUR INSERT SYNTAX IS CORRECT

LET ME KNOW HOW IT GOES

JOHN

 
Old February 14th, 2004, 01:01 AM
Authorized User
 
Join Date: Feb 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I try your suggestion, i input some of my data in my first form and submit the second form come up and the new values doesn't show in the table.
the things is there are no error message until i refresh the second form and i got error message like this:
Error Type:
Provider (0x80004005)
Unspecified error
/Nur/Project_HRD/ViewData.asp, line 23

Browser Type:
Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)

Page:
POST 733 bytes to /Nur/Project_HRD/ViewData.asp

POST Data:
Nomer=2&EmployeeNo=234&Surname=Sena&GivenName=Daul ay&Status=Permanent+Employee&Section=COR&Address=J akarta&WorkLocation=Jakarta&DateofHired=02%2F03%2F 2003&ProjectNo=123&Citizen=Indonesia&PlaceofBirth= . . .

is that mean my insert syntax still have an error?

 
Old February 20th, 2004, 04:48 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 171
Thanks: 0
Thanked 1 Time in 1 Post
Default

Here you go shopgirl. You don't need to request Angka from the form as that field is an auto-number field and you cannot insert into it. You also don't need to set session variables for these values. Let me know if this helps.

'==== Page 1 ====

<%
Nomer = Request("Nomer")
EmployeeNo = Request("EmployeeNo")
Surname = Request("Surname")
GivenName = Request("GivenName")
Status = Request("Status")
Section = Request("Section")
Address = Request("Address")
DateofHired = Request("DateofHired")

set rs = server.createobject("adodb.recordset")
sql = "select * from Expat_EmployeeReg"
rs.open sql, "dsn=Insert", 3, 3

rs.addnew
    rs("Nomer") = Nomer
    rs("Surname") = Surname
    rs("GivenName") = GivenName
    rs("Status") = Status
    rs("EmployeeNo") = EmployeeNo
    rs("Section") = Section
    rs("Address") = Address
    rs("DateofHired") = DateofHired
rs.update
%>


'==== Page 2 ====

<table width="100%">
<tr>

<%
set rs = server.createobject("adodb.recordset")
sql = "select * from Expat_EmployeeReg"
rs.open sql, "dsn=Insert"
if not rs.eof then
do while not rs.eof
%>

<td><%=rs("Angka")%></td>
<td><%=rs("Nomer")%></td>
<td><%=rs("Surname")%></td>
<td><%=rs("GivenName")%></td>
<td><%=rs("Status")%></td>
<td><%=rs("EmployeeNo")%></td>
<td><%=rs("Section")%></td>
<td><%=rs("Address")%></td>
<td><%=rs("DateofHired")%></td>

<%
rs.movenext
loop
else
%>

<td colspan="9">There are no records for the criteria that you have selected.</td>

<%
end if
rs.close
set rs = nothing
%>

</tr>
</table>
 
Old February 24th, 2004, 01:58 AM
Authorized User
 
Join Date: Feb 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I did try your code but my computer doesn't suppport Addnew method thank's DaveGerard and I did figure out how to insert datas by using SQL syntax I put my Access table in the wrong directory and I also make some changes with my database connection. instead using DSN Know I'm using Microsoft Jet OLEDB 4.0 and it's work.
thank's guys





Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert ASP code in JS *need HELP* deean Classic ASP Basics 16 June 28th, 2008 08:57 AM
insert same data to another remo MySQL 2 July 20th, 2007 12:08 AM
Combobox Select/Insert Code osemollie Pro VB Databases 4 June 28th, 2006 09:09 AM
insert word files thru code geetabajpai VB How-To 0 October 7th, 2005 04:22 AM
code for insert query shabirmaher General .NET 1 August 8th, 2005 08:20 AM





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