数据库更新问题 [英] database update issue

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

问题描述

问候。

我遇到一段代码问题,我希望有人可以告诉我哪里出错了。基本上我从一个具有相同项目编号的表中选择了9行数据,但每行都有一个唯一的GUID,然后我遍历数据以在网页上显示它。一切正常。


当我尝试将所有数据(已更改或未更改)提交回表格时,会出现问题。我的提交代码如下:


strcreative_id = Request.Form(" creative_id")

strcreative_runtime = Request.Form(" creative_runtime" )

strcreative_state =的Request.Form(QUOT; creative_state")

strcreative_text_data = REPLACE(的Request.Form(QUOT; creative_text_data")," '' "," ; '' '' ")

strcreative_text_effects =的Request.Form(QUOT; creative_text_effects")

strcreative_image_name =的Request.Form(QUOT; creative_image_name")

strcreative_guid = Request.Form(" creative_guid")

''构建我们的SQL字符串

strSQL =""

strSQL = strSQL& UPDATE tbl_advert_setup_creatives

strSQL = strSQL& SET creative_runtime =''" &安培; strcreative_runtime& "''"

strSQL = strSQL& ","

strSQL = strSQL& " creative_state =''" &安培; strcreative_state& "''"

strSQL = strSQL& ","

strSQL = strSQL& " creative_text_data =''" &安培; strcreative_text_data& ""

strSQL = strSQL& ","

strSQL = strSQL& " creative_text_effects =''" &安培; strcreative_text_effects& ""

strSQL = strSQL& ","

strSQL = strSQL& " creative_image_name =''" &安培; strcreative_image_name& "''"

strSQL = strSQL& Where creative_guid =''" &安培; strcreative_guid& "'';"


Response.Write strSQL


%>



Response.Write产生这个:


UPDATE tbl_advert_setup_creatives SET creative_runtime =''30,60,23,60,240,33,90,22,60'', creative_state =''1,1,1,1,1,0,1,1'',creative_text_data =''轮胎,今天只有!!,今天买一些......请。,75006,Obamas Transition Chief。,Everyone正在审核可以。'',creative_text_effects =''Stretch,Stretch,Inset'',creative_image_name =''2.jpg,3.jpg,5.jpg,1.jpg''While creative_guid =''{B53BA5B7-6971- 4442-9A0F-83EAF27E2F0E},{8E123F5C-25BB-4CCD-A443-77C9D0961002},{53D1FB08-2998-49CB-8D78-D128FAAF6232},{693BD709-C65D-438F-AC3F-817C849B2ECE},{9C7B4C1E-A466-4854- BDCE-250661639490},{27448802-E779-4AFE-A147-41410CEE81A9},{FF4F7F87-1FB2-4902-8055-2F688920A014},{8CBF7404-2CDC-42DC-9DE1-8AEDA0B148DB},{4440412C-951C-46BF-8935- F401D850815B},{BEF028CB-DAF3-470E-B18D-DD9806DD9B 04}'';


如何将数据恢复到我的数据库的每个特定行?它试图将所有9行数据填充回第一行。 creative_guid列是一个唯一标识符。

我想我需要某种更新循环语句,但不能解决它。当我添加Do while not Rs.EOF时对于更新(在strcreative_id = Request.Form(creative_id)之上),它表示当对象关闭时不允许操作。 " RS没有尽我所能关闭。


感谢您的帮助。


P

greetings.
I am having an issue with a piece of code, I was hoping someone can show me where I am going wrong. Basically I select 9 rows of data out of a table that have the same item number, but each row has a unique GUIDs, then I loop through the data to display it on a webpage. This all works fine.

The issues comes when I try to submit all the data (changed or not) back into the table. My submit code is below


strcreative_id = Request.Form("creative_id")
strcreative_runtime = Request.Form("creative_runtime")
strcreative_state = Request.Form("creative_state")
strcreative_text_data = Replace(Request.Form("creative_text_data"),"''","'''' ")
strcreative_text_effects = Request.Form("creative_text_effects")
strcreative_image_name = Request.Form("creative_image_name")
strcreative_guid = Request.Form("creative_guid")

'' Build our SQL String
strSQL = ""
strSQL = strSQL & "UPDATE tbl_advert_setup_creatives "
strSQL = strSQL & "SET creative_runtime =''" & strcreative_runtime & "''"
strSQL = strSQL & ", "
strSQL = strSQL & "creative_state =''" & strcreative_state & "''"
strSQL = strSQL & ", "
strSQL = strSQL & "creative_text_data =''" & strcreative_text_data & "''"
strSQL = strSQL & ", "
strSQL = strSQL & "creative_text_effects =''" & strcreative_text_effects & "''"
strSQL = strSQL & ", "
strSQL = strSQL & "creative_image_name =''" & strcreative_image_name & "''"
strSQL = strSQL & "Where creative_guid = ''" & strcreative_guid & "'';"

Response.Write strSQL

%>


The Response.Write produces this:

UPDATE tbl_advert_setup_creatives SET creative_runtime =''30, 60, 23, 60, 240, 33, 90, 22, 60'', creative_state =''1, 1, 0, 1, 1, 0, 1, 1'', creative_text_data =''tires, today only!!, Buy some today...please., 75006, Obamas Transition Chief., Everyone is reviewing can.'', creative_text_effects =''Stretch, Stretch, Inset'', creative_image_name =''2.jpg, 3.jpg, 5.jpg, 1.jpg''While creative_guid = ''{B53BA5B7-6971-4442-9A0F-83EAF27E2F0E}, {8E123F5C-25BB-4CCD-A443-77C9D0961002}, {53D1FB08-2998-49CB-8D78-D128FAAF6232}, {693BD709-C65D-438F-AC3F-817C849B2ECE}, {9C7B4C1E-A466-4854-BDCE-250661639490}, {27448802-E779-4AFE-A147-41410CEE81A9}, {FF4F7F87-1FB2-4902-8055-2F688920A014}, {8CBF7404-2CDC-42DC-9DE1-8AEDA0B148DB}, {4440412C-951C-46BF-8935-F401D850815B}, {BEF028CB-DAF3-470E-B18D-DD9806DD9B04}'';

How do I get the data back into each specific row of my db? It is trying to stuff all 9 rows of data back into the first row. The creative_guid column is a unique identifier.
I guess I need some sort of update loop statement, but can?t figure it out. when i add "Do while not Rs.EOF" to the update (above strcreative_id = Request.Form("creative_id")) it says "Operation is not allowed when the object is closed. " the RS is not closed as best as i can tell.

thanks for any help.

P

推荐答案

你有一个复杂的问题。在这个答案中我提供了一个可能的解决方我不是100%我的解决方案是你所寻找的,因为你如何陈述你的问题。如果我的解决方案不是您需要的,请修改您的第一篇文章。


是否所有值都应该只存储在一条记录中?当您从具有多个条目的查询字符串或表单请求某些内容时,该脚本将返回一个逗号分隔值的字符串。


您的SQL语句似乎有错误。你在那里有''While''这个词,而我相信你的意思是''在哪里'。


如果你想更新每一行,是的,你会的需要一个循环,每次迭代都执行一个唯一的UPDATE SQL语句。但是,要做到这一点,您必须从Request数据中提取唯一值。这似乎表明你需要拆分()字符串。


我将构建一个如何进行循环的示例更新。

You have a complex problem. In this answer I provide a possible solution. I am not 100% my solution is what you looking for because of how you stated your problem. If my solution isn''t what you need, please revise your first post.

Are all of the values supposed to be stored in only one record like that? When you Request something from the querystring or form that has multiple entries, the script will return a string of comma separated values.

Your SQL statement appears to have an error in it. You have the word ''While'' in there, whereas I believe you meant to have ''WHERE''.

If you mean to update each individual row, yes, you will need a loop that executes a unique UPDATE SQL statement each iteration. To do that, however, you''ll have to pull out the unique values from your Request data. That seems to indicate you''ll need to Split() the strings.

I''m going to construct an example of how to do the looping update.

展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号


Nicodemas,谢谢你的回复。

我想在我的经验不足的情况下,我会以错误的方式解决这个问题。我会尽快尝试你的解决方案,但我试图拥有的是一个包含40个不同可更新字段的网页。

这是我去年建立的现有(正常运行)应用程序的升级版。不同之处在于旧应用程序有1行数据,其中包含42列。这限制了我,因为我找不到从行中提取所有数据的有效方法。例如:有9列,如xxx_state,xxy_state,xzy_state等。所以得到一个查询显示所有状态为1或0的列是一个痛苦。

Nicodemas, thanks for your reply.
I think in my inexperience I am going about this the wrong way.I will try your solution ASAP, but what I am attempting to have is a webpage with 40 different updatable fields in it.
This is an upgrade to an existing (functioning) app I built last year. The difference is that the old app had 1 row of data with 42 columns in it. This limited me because I could not find efficient ways to pull out all the data from the row. For instance: there are 9 columns that are like xxx_state, xxy_state, xzy_state and so on. So getting a query out that showed all the columns that had a state of 1 or 0 was a pain.

展开 | < span class =codeLinkonclick =selectAll(this);>选择 | Wrap | 行号


这看起来像是一件苦差事,但是你能否让我深入了解你存储的数据与哪些相关?我问的原因是,我是否可以围绕你想要做的事情,我将能够尽我所能。我知道你正试图尽可能地解释它,但是我无法理解这个想法。


例如,如果表 tbl_Things 有这些字段:

* numArms

*年龄

*生日

*名称


我可以肯定地说, tbl_Things 中的每一行都描述了人类的属性。你的表格的每一行描述了什么?
It might seem like a chore, but can you give me some insight into what the data you are storing is relevant to? The reason I ask is if I can wrap my head around what you are trying to do I''ll be able to help at my fullest. I know you are trying to explain it as best you can, but I am having trouble picking up the idea.

For instance, if table tbl_Things had these fields:
*numArms
*age
*birthday
*name

I could say with some confidence that each row in tbl_Things described a attributes of a human. What does each row of your table describe?


这篇关于数据库更新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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