将数据插入数据库时​​出错 [英] Problem inserting data to database

查看:65
本文介绍了将数据插入数据库时​​出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个内联网。使用HTML,SQL和ASP。我用SQL创建了一个表就好了。设计一个表格对我来说很好看。但是,当我尝试将数据插入SQL时,我只有错误。按下提交按钮时出现错误。但是,当我使用此网址调用它时,请点击 http://10.164.1.86/lala.asp。它插入信息后产生我希望它产生的massege。希望你能帮忙。我的代码在这里看到这个。


[HTML]<%


Catergory = Trim(Request.Form(") ;注册表))

如果Catergory =" Title"那么

Title = Trim(Request.Form(" Title"))

Author = Trim(Request.Form(" Author"))

ISBN = Trim(Request.Form(ISBN))

Publisher = Trim(Request.Form(" Publisher"))

Place_of_Publication = Trim (Request.Form(出版地点))

年=修剪(Request.Form(" Year))

Collat​​ion = Trim(Request.Form) (整理))

Shelf_Number = Trim(Request.Form(Shelf Number))


如果标题<>" "和作者<>""和ISBN<>""和发布商<>""和Place_of_Publication<>""和年<>""和整理<>""和Shelf_Number<>""然后


%>


MyStatement ="插入Book_files设置值

Title =''" & Title&"'',Author =''"& Author&"'',ISBN =''"& ISBN&"'',Publisher =''"& Publisher& ",Place_of_Publication ="&安培; PlaceofPublication&安培;",年份="&安培;年份&安培;",归类=" &安培;核对&安培;",Shelf_Number ="&安培; ShelfNumber&安培;""


<%


Set Con = Server.CreateObject(" ADODB.Conection")

Con 。打开PROVIDER = SQLOLEDB; DATA SOURCE = master; UID = sa; PWD = sa; DATABASE = Book_files


Con.Execute MyStatement


结束IF

结束IF





%>


< Html>

< Head>< Title>插入数据< / Title>< / Head>

< Body> ;

< Form Method =" POST" action.asp? /registry.html><Head> <中心],[ < Font Color =" Brown" Size = 11 Face =" Comic Sans Ms">

确认页面< /字体> < / center>


< Body BGColor ="黄色">

< Br>< Br>


<%


Response.Write(您的价值已成功插入表格中!)






%>


< ; / Body>


< / Html>

[/ HTML]

I have developed a intranet . Using HTML , SQL and ASP . I have created a table with SQL is just fine . And design a form is just looks fine to me . But when I try to insert Data into the SQL I just have the Error . The Error appears when I press submit button . But when i just call it using this url http://10.164.1.86/lala.asp . It produce the massege i want it to produce after inserting the information. Hope you can help . My Code looks this one here .


[HTML] <%

Catergory = Trim(Request.Form("registry"))
If Catergory= "Title" then
Title = Trim(Request.Form("Title"))
Author = Trim(Request.Form("Author"))
ISBN = Trim(Request.Form("ISBN"))
Publisher= Trim (Request.Form("Publisher"))
Place_of_Publication= Trim(Request.Form("Place of Publication"))
Year=Trim(Request.Form("Year"))
Collation=Trim(Request.Form("Collation"))
Shelf_Number=Trim(Request.Form("Shelf Number"))

If Title <>"" and Author <>"" and ISBN <>"" and Publisher <>"" and Place_of_Publication <>"" and Year <>"" and Collation <>"" and Shelf_Number<>"" Then

%>

MyStatement = "Insert into Book_files Set Values
Title=''"&Title&"'',Author=''"&Author&"'', ISBN=''"&ISBN&"'',Publisher=''"&Publisher& "'',Place_of_Publication=''"& PlaceofPublication&"'',Year=''"&Year&"'',Collation=''" & Collation&"'',Shelf_Number=''"&ShelfNumber&"''"

<%

Set Con = Server.CreateObject("ADODB.Conection")
Con.Open "PROVIDER=SQLOLEDB;DATA SOURCE=master;UID=sa;PWD=sa;DATABASE=Book_files"

Con.Execute MyStatement

End IF
End IF





%>

<Html>
<Head><Title>Insert Data</Title></Head>
<Body>
<Form Method="POST" action.asp? /registry.html><Head> <Center> <Font Color="Brown" Size=11 Face="Comic Sans Ms">
Confirmation Page </Font> </Center>

<Body BGColor="Yellow">
<Br><Br>

<%


Response.Write(" Your Value Has Been Successfully Inserted In The Table!")







%>


</Body>

</Html>
[/HTML]

推荐答案

你的代码看起来不错。当你转到网页时,你得到了满意的答复,因为数据库连接在if ... then语句中,所以只需浏览到那个页面即可跳过那部分代码。


你得到什么错误?可能有一个非常简单的解释。我不确定它会有所帮助,但我愿意告诉你我是如何编码的,我的插入行有点不同。我确定没有正确的方法,但尝试不同的方式也不会受到伤害。


Jared
Your code looks OK to me. You get the satisfactory response when you just go to the web page because the db connection is within an if...then statement, so just browsing to that page skips that part of the code.

What error are you getting? There might be a very simple explanation. I''m not sure it would help, but I''m willing to show you how I tend to code this, I write my insert lines a bit differently. I''m sure there''s not a right way, but trying it differently couldn''t hurt.

Jared


什么这一行是什么意思?

Form Method =" POST" action.asp? /registry.html
What does this line mean ?
Form Method="POST" action.asp? /registry.html


你好吧


当我执行它时,希望它会告诉我结果已插入到数据库中,它只是显示asp的代码而不是确认按摩。就像你在数据库中插入值一样。我现在已经尝试了很长时间了。你可以试一试,告诉我它确实有效。
Hello there

When I execute it , Hoping it will show me that the result is inserted into the database , It just show the code of asp instead of confirmation massage . Like you values are inserted in the database . I had been trying this for a long time now . Can you Please try it and tell me it did work.


这篇关于将数据插入数据库时​​出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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