simple database error

S

Sanju

Hai,to every one

here is my question

I have designed the coding to collect the feedback report from the user
,which includes Name of the user, staffno and comments.But when I click on
submit button I am getting the following error


Error type :
Microsoft Jet Database Engine (0*80040E14)
Number of querty values and the desatination feilds are not the same
/report/formreport.asp,Line 2
---------------------------------------------------------------------------------------------------------------------------------------------------------
The coding is shown below



<html>
<% @LANGUAGE="VBScript" %>
<body>
<%
' Declaring variables
Dim username, userstaffno, usercomments, data_source,
con, sql_insert

' A Function to check if some field entered by user is
empty
Function ChkString(string)
If string = "" Then string = " "
ChkString = Replace(string, "'", "''")
End Function

' Receiving values from Form
username = ChkString(Request.Form("username"))
userstaffno = ChkString(Request.Form("userstaffno"))
usercomments = ChkString(Request.Form("usercomments"))


data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=" &_
Server.MapPath("formreport.mdb")

sql_insert = "insert into formreport
(username,userstaffno,usercomments)"
sql_insert = sql_insert & " values (' " &
Request.Form("username") & " ' , ' " & Request.Form("userstaffno") & " ' , '
" & Request.Form("usercomments") & " ' , ' " & " ' )"

' Creating Connection Object and opening the database
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source
con.Execute sql_insert

' Done. Close the connection
con.Close
Set con = Nothing
Set sql_insert = Nothing
Response.Write "All records were successfully entered
into the database."
%>
</body>
</html>


Can any one please help me
Thanks in advance
 
S

Stuart McCall

Sanju said:
Hai,to every one

here is my question

I have designed the coding to collect the feedback report from the user
,which includes Name of the user, staffno and comments.But when I click on
submit button I am getting the following error


Error type :
Microsoft Jet Database Engine (0*80040E14)
Number of querty values and the desatination feilds are not the
same
/report/formreport.asp,Line 29
---------------------------------------------------------------------------------------------------------------------------------------------------------
The coding is shown below



<html>
<% @LANGUAGE="VBScript" %>
<body>
<%
' Declaring variables
Dim username, userstaffno, usercomments, data_source,
con, sql_insert

' A Function to check if some field entered by user is
empty
Function ChkString(string)
If string = "" Then string = " "
ChkString = Replace(string, "'", "''")
End Function

' Receiving values from Form
username = ChkString(Request.Form("username"))
userstaffno = ChkString(Request.Form("userstaffno"))
usercomments =
ChkString(Request.Form("usercomments"))


data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=" &_
Server.MapPath("formreport.mdb")

sql_insert = "insert into formreport
(username,userstaffno,usercomments)"
sql_insert = sql_insert & " values (' " &
Request.Form("username") & " ' , ' " & Request.Form("userstaffno") & " ' ,
'
" & Request.Form("usercomments") & " ' , ' " & " ' )"

' Creating Connection Object and opening the database
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source
con.Execute sql_insert

' Done. Close the connection
con.Close
Set con = Nothing
Set sql_insert = Nothing
Response.Write "All records were successfully
entered
into the database."
%>
</body>
</html>


Can any one please help me
Thanks in advance

The problem is that you're specifying 3 fields to receive the data and
passing 4 values. The values section of your SQL string needs to look like:

sql_insert = sql_insert & " values (' " &
Request.Form("username") & " ' , ' " & Request.Form("userstaffno") & " ' , '
" & Request.Form("usercomments") & " ' )"

Incidentally, to help avoid this kind of mistake, it would help to lay out
the code like this:

sql_insert = sql_insert & " values (' " & _
Request.Form("username") & " ' , ' " & _
Request.Form("userstaffno") & " ' , ' " & _
Request.Form("usercomments") & " ' " & _
")"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top