|
 |
asp_databases thread: problem in inserting dato in MS Acess
Message #1 by "tulasi" <lakshmi.jonnadula@w...> on Fri, 29 Mar 2002 09:35:59
|
|
help
i m a beginnar in asp.i was trying to insert a value into data base
by using request.form.i m checking 2 cases
1.if null form is submit, i want to display error message(in the same form)
2.if the data i m trying to insert into database is already exiting
i want to display error message (in the same page)
if neither of these not true i want to exectute insert statment.
i m getting the fellowing error message:
_______________________________________________
Error Type:
Microsoft JET Database Engine (0x80004005)
Field 'folder.foldername' cannot be a zero-length string
code:
________________
<%
dim conn
dim rs
dim sql
sql="select * from folder"
set conn=server.createObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.open "d:\tulasi\tulasi.mdb"
set rs=server.createObject("ADODB.recordset")
rs.open sql,conn
%>
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>
<body>
<form method="POST" action="test.asp" name="form1">
<p>Enter folder name:<input type="text" name="T1" size="20"></p>
<p>
&nb
sp;
<input type="submit" value="Submit" name="B1"></p>
</form>
<%
folder=Request.form("T1")
while not rs.EOF
if rs("foldername")= " " then %>
no data entered
<%else
if rs("foldername")=folder then %>
folder already exits..try another name
<% response.redirect("test.asp")
else
conn.execute("insert into folder values('"&folder&"')")
response.redirect("test.asp")
end if
end if
rs.MoveNext
wend
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
</body>
</html>
plz help me in solving this problem.
Thanks
Tulasi.
Message #2 by "Kim Iwan Hansen" <kimiwan@k...> on Fri, 29 Mar 2002 14:43:35 +0100
|
|
Although you keep both the form and the database checking/insertion code on
the same asp page, you can't execute both at the same time (and get your
desired result) - You need to display first the part of the page that makes
up the form, and then, when you submit the form, execute the database
checking/insertion.
Something like this:
IF FORM WAS SUBMITTED THEN
do database work
ELSE
display form
END IF
One way to check if the form was submitted is to check for the length of it:
IF Len(Request.Form) > 0 THEN 'the form was submitted
Also, instead of selecting * from folders, try and select foldername from
folders where foldername = '" & request.form("foldername") & "'"
If you get an empty recordset (i.e. rs.eof), then you know there was no
match - so you can insert the new foldername
If you get something back (i.e. not rs.eof), then you know the folder
already exists - so you don't want to insert the foldername
Don't forget to fix the apostrophe (') security issue with the input from
the form before you do the database work - e.g. in the beginning of the
page:
strFolderName = Replace(Request.Form("foldername"),"'","''")
(And don't forget to replace the "request.form("folders")" in the sql with
strFolderName)
Don't forget to close connections and recordsets and set them to nothing
when you're done with them.
Hope this will help you a bit of the way :o)
-Kim
-----Original Message-----
From: tulasi [mailto:lakshmi.jonnadula@w...]
Sent: 29. marts 2002 09:36
To: ASP Databases
Subject: [asp_databases] problem in inserting dato in MS Acess
help
i m a beginnar in asp.i was trying to insert a value into data base
by using request.form.i m checking 2 cases
1.if null form is submit, i want to display error message(in the same form)
2.if the data i m trying to insert into database is already exiting
i want to display error message (in the same page)
if neither of these not true i want to exectute insert statment.
i m getting the fellowing error message:
_______________________________________________
Error Type:
Microsoft JET Database Engine (0x80004005)
Field 'folder.foldername' cannot be a zero-length string
code:
________________
<%
dim conn
dim rs
dim sql
sql="select * from folder"
set conn=server.createObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.open "d:\tulasi\tulasi.mdb"
set rs=server.createObject("ADODB.recordset")
rs.open sql,conn
%>
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>
<body>
<form method="POST" action="test.asp" name="form1">
<p>Enter folder name:<input type="text" name="T1" size="20"></p>
<p>
&nb
sp;
<input type="submit" value="Submit" name="B1"></p>
</form>
<%
folder=Request.form("T1")
while not rs.EOF
if rs("foldername")= " " then %>
no data entered
<%else
if rs("foldername")=folder then %>
folder already exits..try another name
<% response.redirect("test.asp")
else
conn.execute("insert into folder values('"&folder&"')")
response.redirect("test.asp")
end if
end if
rs.MoveNext
wend
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
</body>
</html>
plz help me in solving this problem.
Thanks
Tulasi.
|
|
 |