473,788 Members | 3,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

database update issue

18 New Member
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("c reative_id")
strcreative_run time = Request.Form("c reative_runtime ")
strcreative_sta te = Request.Form("c reative_state")
strcreative_tex t_data = Replace(Request .Form("creative _text_data"),"' ","''")
strcreative_tex t_effects = Request.Form("c reative_text_ef fects")
strcreative_ima ge_name = Request.Form("c reative_image_n ame")
strcreative_gui d = Request.Form("c reative_guid")

' Build our SQL String
strSQL = ""
strSQL = strSQL & "UPDATE tbl_advert_setu p_creatives "
strSQL = strSQL & "SET creative_runtim e ='" & strcreative_run time & "'"
strSQL = strSQL & ", "
strSQL = strSQL & "creative_s tate ='" & strcreative_sta te & "'"
strSQL = strSQL & ", "
strSQL = strSQL & "creative_text_ data ='" & strcreative_tex t_data & "'"
strSQL = strSQL & ", "
strSQL = strSQL & "creative_text_ effects ='" & strcreative_tex t_effects & "'"
strSQL = strSQL & ", "
strSQL = strSQL & "creative_image _name ='" & strcreative_ima ge_name & "'"
strSQL = strSQL & "Where creative_guid = '" & strcreative_gui d & "';"

Response.Write strSQL

%>


The Response.Write produces this:

UPDATE tbl_advert_setu p_creatives SET creative_runtim e ='30, 60, 23, 60, 240, 33, 90, 22, 60', creative_state ='1, 1, 0, 1, 1, 0, 1, 1', creative_text_d ata ='tires, today only!!, Buy some today...please. , 75006, Obamas Transition Chief., Everyone is reviewing can.', creative_text_e ffects ='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("c reative_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
Jan 6 '09 #1
10 2234
Nicodemas
164 Recognized Expert New Member
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.

Expand|Select|Wrap|Line Numbers
  1. '// imagine this assigns "{ABC}, {XYZ}"
  2. dim myGUIDs : myGUIDs = request.form("theGUIDs")
  3.  
  4. '// imagine this assigns "John Smith, Sacajawea"
  5. dim myValues : myValues = request.form("theValues")
  6.  
  7. '// returns 
  8. '// myGUID(0) = "{ABC}" 
  9. '// myGUID(1) = "{XYZ}"
  10.  
  11. myGUID = split(myGUIDs, ",") 
  12.  
  13. '// returns 
  14. '// myValue (0) = "John Smith"
  15. '// myValue(1) = "Sacajawea"
  16.  
  17. myValue = split(myValues, ",") 
  18.  
  19. for x = 0 to 1
  20.    sSQL = "UPATE myTable SET myName = '"& replace(myValue(x), "'", "") &"' WHERE myID = "& replace(myGUID(x), "'", "")
  21.  
  22.    myConnection.execute(sSQL)
  23. next
  24.  
Jan 8 '09 #2
Path9898
18 New Member
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.

Expand|Select|Wrap|Line Numbers
  1.  sqlstmt = "SELECT Screen_Location, Temperature_name, Temperature_zip_code, CL_name, CL_state,
  2.  CL_runtime, BText_name, BText_text, BText_State, Picture_name1, Picture_state1, Picture_runtime1, 
  3. Picture_name2, Picture_state2, Picture_runtime2, Picture_name3, Picture_state3, Picture_runtime3, 
  4. Picture_name4, Picture_state4, Picture_runtime4, Picture_name5, Picture_state5, Picture_runtime5, 
  5. Text_name1, Text_state1, Text_runtime1, Text_text1, Text_texteffect1, Text_name2, Text_state2, 
  6. Text_runtime2, Text_text2, Text_texteffect2, Text_name3, Text_state3, Text_runtime3, Text_text3, 
  7. Text_texteffect3 FROM tbl_A_Details WHERE business_GUID='{"& URLBusiness_GUID &"}' 
  8. AND gAD_GUID='{"& URLgAD_GUID &"}' ;" 
So I am attempting to redesign the DB structure so there is 1 state column, 1 name column, 1 type col and so on, (although not all the columns have data in them), with relevant data spread across different rows. About 11 rows match the query because they all are linked by a guid that is in the URL query string.
Expand|Select|Wrap|Line Numbers
  1.  sqlstmt = "select business_guid, gAD_guid, creative_guid, creative_name, creative_id, 
  2. creative_runtime, creative_state, creative_type, creative_text_data, creative_text_effects, 
  3. creative_image_name from tbl_advert_setup_creatives where gAD_guid = '{"& URLgAD_GUID &"}' 
  4. order by creative_id asc;" 
I then loop through and build the webpage using the results. In the end there is a single button to update all the values that exist on the page.
How do you pro’s do this?
Jan 9 '09 #3
Nicodemas
164 Recognized Expert New Member
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?
Jan 9 '09 #4
Path9898
18 New Member
the table holds information for a web based image and text slide show. The slide show duration, images, text, colors and animations are controlled by the settings entered in the page i have been struggling with

So there are the names of 5 different images, times that each images will appear in a web slide show, 3 different pieces of text, 3 text animation names. Then the data is selected and run in the slide show based on the slide show's unique guid. A lot of the data is repeated in many columns in the current version (Picture_name1, Picture_name2, Picture_name3, Picture_name4, Picture_state1, Picture_state2, Picture_state3, Picture_state4) and will be replace by more generic col names likes creative_image_ name, creative_state.
the images are not kept in the DB, just the path's to them. Unfortunately I can't provide a link to show you it, my company would have a fit.
Jan 9 '09 #5
Path9898
18 New Member
Nicodemas
I updated my code using your example and it works great! thank you for helping me. I am still keen to know if i am going about this the correct way though.
One issue i found was that if any of my text fields have a sentance in it like "hello, world" the split() chops it up. Is there a way around this?

Path
Jan 11 '09 #6
Nicodemas
164 Recognized Expert New Member
There is a way! If there is more than one field with the same name attribute in form, that becomes an array automatically through the Request object.

See this code example:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3.    <form method="post" action="_requesttest.asp">
  4.       <input type="checkbox" name="chkTest" value="Alpha" /><br />
  5.       <input type="checkbox" name="chkTest" value="Bravo, Bravo!" /><br />
  6.       <input type="checkbox" name="chkTest" value="Charlie" /><br />
  7.       <input type="checkbox" name="chkTest" value="Delta" /><br />
  8.       <input type="submit" />
  9.    </form>
  10.  
  11.    <h3>Count: <%= request.form("chkTest").count %></h3>
  12.  
  13.    <h3>List:</h3>
  14.    <ol><%
  15.       for x = 1 to request.form("chkTest").count
  16.          response.write "<li>" & request.form("chkTest")(x) & "</li>"
  17.       next
  18.    %></ol>
  19. </body>
  20. </html>
  21.  
See that there are multiple checkboxes with the same NAME attribute. I can access the individual values of all the checkboxes by iterating through the Request.Form("c hkTest") array that was automatically built by the web server.

Notice the array is NOT ZERO BASED! Unlike everything we know to be standard in arrays, the request array starts with one instead of zero. I exploit this by starting my For() loop by setting x = 1, not zero.

This is the amended code. I can't believe I didn't think about this before. I knew about it, but for some reason it skipped my mind. It'll capture your entire form data, and not Split() things unevenly.

Expand|Select|Wrap|Line Numbers
  1. '// request.form("theGUIDs")(1) = "{ABC}"
  2. '// request.form("theGUIDs")(2) = "{XYZ}"
  3.  
  4. dim myGUIDs : myGUIDs = request.form("theGUIDs")
  5.  
  6. '// request.form("theValues")(1) = "John Smith"
  7. '// request.form("theValues")(2) = "Sacajawea"
  8.  
  9. dim myValues : myValues = request.form("theValues")
  10.  
  11. for x = 1 to 2
  12.    sSQL = "UPATE myTable SET myName = '"& replace(myValues(x), "'", "") &"' WHERE myID = "& replace(myGUID(x), "'", "")
  13.  
  14.    myConnection.execute(sSQL)
  15. next
  16.  
Jan 15 '09 #7
Path9898
18 New Member
Nicodemas, thanks for the update. I tried integrating your examples into my code and don’t think I have done it correctly. While the updated code does function and inserts all 11 rows of updates I am having issues with apostrophes.
Here is my new update statement
Expand|Select|Wrap|Line Numbers
  1. for x = 1 to 11
  2. strSQL = "UPDATE tbl_advert_setup_creatives SET  " & _
  3. "creative_runtime = '"& replace(request.form("creative_runtime")(x),"'","") &"', " & _
  4.  "creative_state = '"& replace(request.form("creative_state")(x),"'","") &"', " & _
  5.  "creative_text_data = '"& replace(request.form("creative_text_data")(x),"'","`") &"', " & _
  6.  "creative_text_effects = '"& replace(request.form("creative_text_effects")(x),"'","") &"', " & _
  7.  "creative_image_name = '"& replace(request.form("creative_image_name")(x),"'","") &"' " & _
  8.  "WHERE creative_guid = '"& replace(request.form("creative_guid")(x),"'","") & "';"
  9.   conn.execute(strSQL), lngRecsAffected, adCmdText Or adExecuteNoRecords
  10.  next
  11.  
This seems to be a far cry from your example but it was the only way I could make it work.
Is this a suitable method of doing this?


Apostrophe Issue:
If someone enters "She’s Hot!", the database saves “She” and “s Hot!” in 2 different database cells creating all kinds of fun issues.
I have tried to correct it but replace ‘ with ` (on the tilde key) with
Expand|Select|Wrap|Line Numbers
  1. "creative_text_data = '"& replace(request.form("creative_text_data")(x),"’","`") &"', " & _
  2.  
This works but is not ideal.

I also tried this
Expand|Select|Wrap|Line Numbers
  1. "creative_text_data = '"& replace(request.form("creative_text_data")(x),"’","(apost)") &"', " & _
  2.  
And then use this at the top of the form after the select statement to replace (apost) with a ’
Expand|Select|Wrap|Line Numbers
  1. 'strcreative_text_data         = Replace(RS("creative_text_data"),"(apost)","’")
  2.  
This fails because on page load it splits the field at the apostrophe and shows only “She” while the “s Hot!” missing is are all the creative_text_d ata fields because they have been saved into the incorrect cells.
Is this fixable or will i need to continue using the ` (tilde key) replace method?

Thanks
Jan 18 '09 #8
Nicodemas
164 Recognized Expert New Member
Instead of replacing apostrophes with empty strings, replace it with two apostrophes.

Expand|Select|Wrap|Line Numbers
  1. str = replace(str, "'", "''")
Jan 19 '09 #9
Path9898
18 New Member
I tired that using
Expand|Select|Wrap|Line Numbers
  1. "creative_text_data = '"& replace(request.form("creative_text_data")(x),"'","''") &"',
  2.  
but when I view the database I can see that only one ' gets saved into the cell.
For example if I enter and submit "these cat's rock" I thought it would save "these cat''s rock" in the database, but it saves "these cat's rock" and webpage displays "these cat" only.

What am I missing?
Jan 20 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

16
7522
by: noah | last post by:
Does PHP have a feature to associate Cookie sessions with a persistent database connection that will allow a single transaction across multiple HTTP requests? Here is how I imagine my process: I have an series of interactive HTML forms. The user begins a Cookie session. A database connection is opened and a transaction is begun. After the user goes through any number of pages where they update the database they finish on a page where...
4
2626
by: Frnak McKenney | last post by:
I'm using an in-core DataSet as an image of my application's 'database' (a multi-table Access97 mdb file). Updates are made to the DataTables within the DataSet via forms with bound TextBoxes, then written to the database... or at least that's what's supposed to be happening. Unfortunately, I've discovered that while it appears that when I create a new record/row I'm successfully updating the Access database, once the Update is...
2
4869
by: vrbala | last post by:
Hi All, I have a issue in federated database. I will explain the scenario I have a table T1 in database called offlinedb. It has one column F1 I have an another table T2 in database uatdb. I added attached table T1 in offlinedb using Federated Objects. Then i created a procedure P1 in uatdb database with the following contents.
3
13086
by: Tc | last post by:
Hi, I was curious, I am thinking of writing an application that loads a dataset from a database that resides on a server. The question I have is this, if multiple copies of the app will be running at once will there be problems with data updates? The reason I ask is I'm thinking like this: User1 launches the app and the dataset is created from the data in the DB.
3
1632
by: Simon | last post by:
Hi everyone, I have a small problem regarding a wizard that I'm making on my website. The wizard is obviously a series of pages that take values from the user. My question is: - Should I store all the values entered until the last page and then update the database, or should I do it as I go.
13
2672
by: Lyners | last post by:
I have a web page writen in ASP.NET that contains some javascript so that when a user presses a button, or edits a certain field in a datagrid, another cell in the datagrid is filled with a value. My probelm.... when I have the user press the update button (which does a post back that loops through the datagrid and updates a database) the field/cell that is filled by the javascript appears to be blank in my update code, even though I can...
0
1511
by: Gagan Sindhu Dewangan | last post by:
Below is the following procedure where I am facing the problem, the work of the below procedure is to update the database. query result:sp_helptext bProjectUpdate Text ...
10
4303
by: shsandeep | last post by:
The ETL application loaded around 3000 rows in 14 seconds in a Development database while it took 2 hours to load in a UAT database. UAT db is partitioned. Dev db is not partitioned. the application looks for existing rows in the table...if they already exist then it updates otherwise inserts them. The table is pretty large, around 6.5 million rows.
25
2813
by: pereges | last post by:
Hello, I'm trying to build a database driven website for a library management system. The database is stored on a remote server which all of my team mates can access. I've installed MySQL, PHP and Apache on my machine. I'm a beginner and I really don't understand how to proceed. My biggest problem is how to connect to the database on remote mysql server ? Does php allow this kind of thing ? I'm interested in a web interface on my machine...
0
2904
by: imusion | last post by:
Hi, I have 2 servers each running AIX and both have a DB2 database setup on them. I'm building a news management application and in our setup we need to have a staging and production setup. So the staging database gets the changes performed and then once we're satisfied with how it looks, we push the changes through SQL queries which perform the (deletions, updating, and inserting of articles) onto the production database by comparing it to...
0
9655
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.