Results 1 to 6 of 6

Thread: Arrays and update statements

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2011
    Posts
    4

    Post Arrays and update statements

    I am working on arrays but i need to do a sql update statement.
    Contents of the array are also part a primary key in my table.
    How do I do an update using the array for example if my array is room names and my other table values are start date, end date and campus ID.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Arrays and update statements

    There is no such thing as a database column that contains an array, so what you're talking about doesn't make sense. If you're talking about multiple columns then you need to treat each array element as a separate value, which it is, and insert it into the appropriate column. If you're talking about multiple rows then you need to insert a row for each element in the array.

    If that doesn't answer your question then you need to provide a more detailed explanation of your database and application design.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2011
    Posts
    4

    Unhappy Re: Arrays and update statements

    Quote Originally Posted by jmcilhinney View Post
    There is no such thing as a database column that contains an array, so what you're talking about doesn't make sense. If you're talking about multiple columns then you need to treat each array element as a separate value, which it is, and insert it into the appropriate column. If you're talking about multiple rows then you need to insert a row for each element in the array.

    If that doesn't answer your question then you need to provide a more detailed explanation of your database and application design.
    Code:
    DBConn.BeginTrans
    			'On Error Resume Next
    			'DELETE data
    			strSQL = "DELETE tblAvailable WHERE "
    			strSQL = strSQL + "(intCampusID = " + Session("TypeID") + ")"
    			strSQL = strSQL + " AND (dtm BETWEEN CONVERT(DATETIME,'" + cstr(Year(dtmStart)) + "-" + cstr(Month(dtmStart)) + "-" + cstr(Day(dtmStart)) + "', 102)"
    			strSQL = strSQL + " AND CONVERT(DATETIME,'" + cstr(Year(dtmEnd)) + "-" + cstr(Month(dtmEnd)) + "-" + cstr(Day(dtmEnd)) + "', 102))"
    			
    			
    			'SY SINGH
    			'Add code to only delete out room types contained in the spreadsheet
    			Dim i
    			strSQL = strSQL & "AND (strRoomType='" & strRooms(0) & "'"
    			For i = 1 to m_Rooms
    				strSQL = strSQL & " OR strRoomType='" & strRooms(i) & "'"
    			next
    			strSQL = strSQL & ")"
    			
    			
    			'Response.Write strSQL
    			DBConn.Execute strSQL
    This is the code that was originally there on the system I am working on. I don't want it to do a delete, I instead want it to do an update of the available records using the following quantity
    Code:
    strSQL = "SET intQTY=" + intQuantity(intCurrentData)
    I realised that the previous programmer may have been doing a delete because of the use of arrays for the strRoom data which comes as an array but a delete over writes the exisiting data. I just want to do an update.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2011
    Posts
    4

    Re: Arrays and update statements

    Anybody be able to help me or need further clarification?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Arrays and update statements

    Further clarification. I asked for a more detailed explanation and didn't really get it. Code is all well and good but it is not a substitute for a full and clear explanation of what you actually want to achieve.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2011
    Posts
    4

    Post Re: Arrays and update statements

    Quote Originally Posted by jmcilhinney View Post
    Further clarification. I asked for a more detailed explanation and didn't really get it. Code is all well and good but it is not a substitute for a full and clear explanation of what you actually want to achieve.
    well hopefully this makes sense to you:

    There is an excel workbook in which room type, quantity and rates are entered. That is then exported into an asp page. The different Room types are stored in an array hence the array can have roomtype[0]-max depending on the number of rooms types entered in the excel

    The existing code in the asp page is what I had pasted earlier. It deletes the existing room details that are there and then inserts new data. I do not want to delete the existing data but to update room prices and quantity based on the room type. My primary keys are roomtype, startdate, enddate, campusId. you can see that in the code from earlier

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width