另一个Drop List问题 [英] Another Drop List question

查看:56
本文介绍了另一个Drop List问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有另一个下拉列表问题


我使用下面的代码,用户选择一个名字,但它应该

传递一个名字并通过电子邮件发送到表格


< select name =" user">

< option value ="<%Response.Write( rsUser(" Name"))%>">

<%Response.Write(rsUser(" Name")))%>

< ; input type =" hidden"名称= QUOT;电子邮件与QUOT; value ="<%Response.Write

(rsUser(" Email"))%>">

< / option>

< / select>

当我测试表单作为它生成的源时,一切似乎都没问题

是这样的:


< select name =" user">

< option value =" 1st guy">

1st guy

< input type =" hidden"名称= QUOT;电子邮件与QUOT; value =" 1s ***** @ domain.com">

< / option>


< option value =" 2nd家伙">

第二个家伙

< input type =" hidden"名称= QUOT;电子邮件与QUOT; value =" 2n ***** @ domain.com">

< / option>

< / select>

所以一切看起来都很好,它从第一张

表中提取信息就好了,但当我提交将信息添加到第二张

表时它没有添加电子邮件值,我收到以下错误


Microsoft JET数据库引擎(0x80004005)

字段''Table.Email''不能一个零长度的字符串。


如果我更改表中的电子邮件字段以允许零长度我不会
得到错误,但是电子邮件没有进入表格,只是名称

被添加(它是一个访问2000数据库)


任何想法我做错了什么在这里?


感谢

I''ve got another drop list problem

I am using the following code where users select a name, but it should
pass a name and email into the table

<select name="user">
<option value="<% Response.Write (rsUser("Name")) %>">
<% Response.Write (rsUser("Name")) %>
<input type="hidden" name="Email" value="<% Response.Write
(rsUser("Email")) %>">
</option>
</select>
everything seems to be ok when i test the form as the source it produces
is this:

<select name="user">
<option value="1st guy">
1st guy
<input type="hidden" name="Email" value="1s*****@domain.com">
</option>

<option value="2nd guy">
2nd guy
<input type="hidden" name="Email" value="2n*****@domain.com">
</option>
</select>

so everything seems fine, it is pulling the information from the 1st
table just fine, but when i submit to add the information to the 2nd
table it does not add the email value, i get the following error

Microsoft JET Database Engine (0x80004005)
Field ''Table.Email'' cannot be a zero-length string.

if i change the email field in the table to allow zero length i don''t
get the error, but the email does not go into the table, just the name
is added (it''s an access 2000 database)

any ideas what i am doing wrong here?

thanks

推荐答案

C White写道:

<剪断>>如果我更改表格中的电子邮件字段以允许零长度我不会
C White wrote:
<snip>> if i change the email field in the table to allow zero length i
don''t
得到错误,但电子邮件不会进入表格,只是名称
被添加(这是一个访问2000数据库)

任何想法我在这里做错了什么?
get the error, but the email does not go into the table, just the name
is added (it''s an access 2000 database)

any ideas what i am doing wrong here?



不可能没有说看到用于将数据添加到

数据库的代码

-

Microsoft MVP - ASP / ASP.NET

请回复新闻组。这个电子邮件帐户是我的垃圾邮件陷阱所以我

不经常检查它。如果您必须离线回复,请删除

没有垃圾邮件


Impossible to say without seeing the code used to add the data to the
database

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don''t check it very often. If you must reply off-line, then remove the
"NO SPAM"


抱歉,我不知道是否任何人都想要它,这里是:


<%


''声明你的变量

昏暗姓名,电子邮件

Dim sConnString,connection,sSQL

''从表单接收值,将输入的值赋给变量

Name = Request.Form(" Name")

Email = Request.Form(" Email")

''声明将查询的SQL语句数据库

sSQL =" INSERT into users(Name,Email)values(''"& Name&"'',''"&

电子邮件&"'')"


''定义连接字符串,指定数据库

''驱动程序和数据库的位置

sConnString =" PROVIDER = Microsoft.Jet.OLEDB.4.0;" &安培; _

数据来源= &安培; Server.MapPath(" User_Info.mdb")

''创建一个ADO连接对象

设置连接= Server.CreateObject(" ADODB.Connection")


''打开与数据库的连接

connection.Open(sConnString)


''执行SQL

connection.execute(sSQL)

response.write代理商信息已成功提交。


''完成。关闭连接对象

connection.Close

设置连接=没有

%>


Bob Barrows [MVP]写道:
Sorry bout that, I wasn''t sure if anyone would want it, here it is:

<%

''declare your variables
Dim Name, Email
Dim sConnString, connection, sSQL

'' Receiving values from Form, assign the values entered to variables
Name = Request.Form("Name")
Email = Request.Form("Email")

''declare SQL statement that will query the database
sSQL = "INSERT into users (Name, Email) values (''" & Name & "'', ''" &
Email & "'')"

''define the connection string, specify database
''driver and the location of database
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("User_Info.mdb")
''create an ADO connection object
Set connection = Server.CreateObject("ADODB.Connection")

''Open the connection to the database
connection.Open(sConnString)

''execute the SQL
connection.execute(sSQL)

response.write "The agent information was successfully submitted."

'' Done. Close the connection object
connection.Close
Set connection = Nothing
%>

Bob Barrows [MVP] wrote:
C White写道:
< snip>>如果我更改表格中的电子邮件字段以允许零长度我不会
C White wrote:
<snip>> if i change the email field in the table to allow zero length i
don''t
得到错误,但电子邮件不会进入表格,只是名称
被添加(这是一个访问2000数据库)

任何想法我在这里做错了什么?
get the error, but the email does not go into the table, just the name
is added (it''s an access 2000 database)

any ideas what i am doing wrong here?



不可能没有说看到用于将数据添加到数据库的代码



Impossible to say without seeing the code used to add the data to the
database



" C White"在消息新闻中写道:6c ******************** @ rogers.com ...

:我有另一个下拉列表问题



:我使用下面的代码,用户选择一个名字,但它应该

:传递一个名字和电子邮件到表



:< select name =" user">

:< option value ="<%Response .Write(rsUser(" Name")))%>">

:<%Response.Write(rsUser(" Name")))%>

:< input type =" hidden"名称= QUOT;电子邮件与QUOT; value ="<%Response.Write

:(rsUser(" Email")))%>">

:< / option>

:< / select>

:当我测试表单作为它生成的源时,一切似乎都没问题

:是这样的:



:< select name =" user">

:< option value =" 1st guy">

:第一个人

:< input type =" hidden"名称= QUOT;电子邮件与QUOT; value =" 1s ***** @ domain.com">

:< / option>



:< ; option value =" 2nd guy">

:2nd guy

:< input type =" hidden"名称= QUOT;电子邮件与QUOT; value =" 2n ***** @ domain.com">

:< / option>

:< / select>



:所以一切看起来都很好,它从第一个

:表中提取信息就好了,但当我提交将信息添加到第二个

:表格没有添加电子邮件值,我收到以下错误



:Microsoft JET数据库引擎(0x80004005)

:字段''Table.Email''不能是零长度字符串。



:如果我更改表格中的电子邮件字段允许零长度我没有

:得到错误,但电子邮件没有进入表格,只是名称

:被添加(它'''访问2000数据库)



:任何想法我在这里做错了什么?


两件事:


1.如果您的数据库字段设置为不允许零长度字符串,则它需要数据。
需要数据。这不是您插入数据的代码,它是代码

,其中显示您从数据中收到的值。你有没有验证数据库中没有数据?
?你插入数据时是否收到错误

或者你的

插入代码中是否有On Error Resume Next行吗?


2.我发现它通常更容易,并且可能更少受到性能影响如果

你将HTML放入字符串然后通过例程来传递它们

它到页面。


Ex。


<%@ Language = VBScript%>

< ;%

..

..

..


sub prt(str)

Response.Write(str& vbCrLf)

end sub


dim s

s =" ;< select name ="" user"">" &安培; vbCrLf& _

"< option value =""" &安培; rsUser(名称)& """>" &安培; rsUser(名称)& vbCrLf& _

"< input type ="" hidden""名称= QUOT;"电子邮件与QUOT;"值= QUOT;"" &安培; rsUser(电子邮件)& """>"

& vbCrLf& _

"< / option>" &安培; vbCrLf& _

"< / select>"


prt s


%>


我更喜欢这个因为我的服务器没有来回切换阅读

ASP代码和HTML对我而言,它更容易排列我的报价。我知道我的字符串需要引号,如果我为HTML元素赋值

我需要3,否则,为HTML添加引号意味着我需要2.所以,单个

边缘,2表示所有HTML值,3表示我需要传递值来自

ASP。


这个:

& vbCrLf


....为HTML输出添加一个回车符,换行符,这样代码就更清晰了。它与代码的运行方式无关。


& _可能缩短为_只是_这是一个串联

字符所以VBScript代码可以在下一行恢复。


我正在构建一个字符串传递一次,我的解析器读取整个

页面,而不是来回切换读取ASP,HTML,ASP等。我告诉你这是怎么回事解析器工作。我可以重新定义s如上所述,或者我

甚至可以有一系列的陈述,但它让我能更好地控制我的数据输出




而不是......


<%@ Language = VBScript%>

<%

..

..

..

%>

< select name =" user" >

< option value ="<%Response.Write(rsUser(" Name")))%>">

<% Response.Write(rsUser(" Name")))%>

< input type =" hidden"名称= QUOT;电子邮件与QUOT; value ="<%Response.Write

(rsUser(" Email"))%>">

< / option>

< / select>

<%

....

%>


....至少你可以用=
取代Response.Writes
< select name =" user">

< option value ="<%= rsUser(" Name")%>">

<%= rsUser(" Name")%> ;

< input type =" hidden"名称= QUOT;电子邮件与QUOT; value ="<%= rsUser(" Email")%>">

< / option>

< / select>


HTH ...


-

Roland Hall

/ *此信息分发希望它有用,但

没有任何保证;甚至没有适销性的暗示保证

或特定用途的适用性。 * /

Technet脚本中心 - http:// www .microsoft.com / technet / scriptcenter /

WSH 5.6文档 - http://msdn.microsoft.com/downloads/list/webdev.asp

MSDN Library - http://msdn.microsoft.com/library/default.asp
"C White" wrote in message news:6c********************@rogers.com...
: I''ve got another drop list problem
:
: I am using the following code where users select a name, but it should
: pass a name and email into the table
:
: <select name="user">
: <option value="<% Response.Write (rsUser("Name")) %>">
: <% Response.Write (rsUser("Name")) %>
: <input type="hidden" name="Email" value="<% Response.Write
: (rsUser("Email")) %>">
: </option>
: </select>
: everything seems to be ok when i test the form as the source it produces
: is this:
:
: <select name="user">
: <option value="1st guy">
: 1st guy
: <input type="hidden" name="Email" value="1s*****@domain.com">
: </option>
:
: <option value="2nd guy">
: 2nd guy
: <input type="hidden" name="Email" value="2n*****@domain.com">
: </option>
: </select>
:
: so everything seems fine, it is pulling the information from the 1st
: table just fine, but when i submit to add the information to the 2nd
: table it does not add the email value, i get the following error
:
: Microsoft JET Database Engine (0x80004005)
: Field ''Table.Email'' cannot be a zero-length string.
:
: if i change the email field in the table to allow zero length i don''t
: get the error, but the email does not go into the table, just the name
: is added (it''s an access 2000 database)
:
: any ideas what i am doing wrong here?

Two things:

1. If your database field is set to not allow zero-length strings, then it
needs data. This is not the code where you insert the data, it is the code
where you are showing values you have received from the data. Have you
verified the data is not present in the database? Are you getting an error
when you insert data or do you have an On Error Resume Next line in your
insert code?

2. I have found it is often easier and possibly less of a performance hit if
you put your HTML in strings and then pass them through a routine to write
it to the page.

Ex.

<%@ Language=VBScript %>
<%
..
..
..

sub prt(str)
Response.Write(str & vbCrLf)
end sub

dim s
s = "<select name=""user"">" & vbCrLf & _
"<option value=""" & rsUser("Name") & """>" & rsUser("Name") & vbCrLf & _
"<input type=""hidden"" name=""Email"" value=""" & rsUser("Email") & """>"
& vbCrLf & _
"</option>" & vbCrLf & _
"</select>"

prt s

%>

I like this better because my server is not switching back and forth to read
ASP code and HTML and for me, it makes it easier to line up my quotes. I
know that my string needs quotes and if I assign a value to an HTML element
that I need 3, otherwise, adding quotes for HTML means I need 2. So, single
around the edges, 2 for all HTML values and 3 if I need to pass a value from
ASP.

This:
& vbCrLf

....adds a carriage return, line feed to the HTML output so the code is more
legible. It has nothing to do with how the code runs.

& _ could probably be shortened to just _ which is a concatentation
character so VBScript code can resume on the next line.

I''m building a string that gets passed once and my parser reads the whole
page, rather than switching back and forth to read ASP, HTML, ASP, etc. I
am told this is how the parser works. I could redefine "s" as above, or I
could even have an array of statements, but it gives me better control over
the output of my data.

instead of ...

<%@ Language=VBScript %>
<%
..
..
..
%>
<select name="user">
<option value="<% Response.Write (rsUser("Name")) %>">
<% Response.Write (rsUser("Name")) %>
<input type="hidden" name="Email" value="<% Response.Write
(rsUser("Email")) %>">
</option>
</select>
<%
....
%>

....at the very least you could replace the Response.Writes with =

<select name="user">
<option value="<% = rsUser("Name") %>">
<% = rsUser("Name") %>
<input type="hidden" name="Email" value="<% = rsUser("Email") %>">
</option>
</select>

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp


这篇关于另一个Drop List问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆