[RESOLVED] VB Script will not remove modified data from Database - Page 6
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 6 of 8 FirstFirst ... 345678 LastLast
Results 76 to 90 of 114

Thread: [RESOLVED] VB Script will not remove modified data from Database

  1. #76
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,786

    Re: VB Script will not remove modified data from Database

    btw... this line ....
    Code:
    	If (TypeRS("TypeName") = TypeRS("TypeName")) Then Session("NewName")=TypeRS("TypeName")
    Why on earth did you write the If Test like that? You do know that TypeRS("TypeName") will always = TypeRS("TypeName") as it is the same thing and therefore must be the same so the test is totally useless.

    that line could be written
    Code:
    Session("NewName")=TypeRS("TypeName")
    And get the exact same result
    Always use [code][/code] tags when posting code.

  2. #77
    Join Date
    Jun 2013
    Posts
    102

    Re: VB Script will not remove modified data from Database

    Quote Originally Posted by DataMiser View Post
    Like I said to do a lookup you would do something like
    Code:
    RS.Open "SELECT ColorName FROM LinkColor WHERE ColorCode =" & Request("ColorCode"), Connect, 2, 3
    I'm not sure what you do not understand there, hard to follow your posts sometimes and that code is extremely hard to follow all jumbled together as it is and with me having no idea it that is the complete script, what data is being submitted and what is being passed on if anything.

    Try to keep it simple, focus on one thing at a time and the core of the code.
    Either you have the value you need to display at some point or you need to look it up, those are the only possibilities. The code I showed earlier lets you see the selected color name but apparently that was not what you wanted which means you most likely need to do a lookup hence the select query.

    This query requires you to have the colorcode available and allows you to get the matching colorname from the database which I assume is the case.

    Hi Again and thanks for the prompt reply. I can forget about displaying the newly CHANGED category name in Tpye table because it works fine. The changed Color information is a bit different in the type table in so much as it is given a text value there which has a corresponding value in the LinkColor table called ColorName. I can make it display #000 or a color name but it is still one step behind the actual database information. Do you have any idea what the RS open error is as it may pinpoint the problem??? Where would I use a query database request? on the new page or on the edit page and store it as a session var?

  3. #78
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,786

    Re: VB Script will not remove modified data from Database

    Quote Originally Posted by davida1956 View Post
    Do you have any idea what the RS open error is as it may pinpoint the problem???
    What error are you referring to?

    Where would I use a query database request? on the new page or on the edit page and store it as a session var?
    You would use it where you need the info. You need to have the colorcode available when you do it as that is required to do the lookup. I do not know where all this is available nor am I sure where you want to display this so I can't tell you exactly where to put it based on what I know. I can tell you that if the colorcode is known at the point you want to display the colorname then you can do the lookup there. If not then the lookup would have to be done elsewhere and stored in a variable or session variable depending on where it is used.
    Always use [code][/code] tags when posting code.

  4. #79
    Join Date
    Jun 2013
    Posts
    102

    Re: VB Script will not remove modified data from Database

    Quote Originally Posted by DataMiser View Post
    What error are you referring to?



    You would use it where you need the info. You need to have the colorcode available when you do it as that is required to do the lookup. I do not know where all this is available nor am I sure where you want to display this so I can't tell you exactly where to put it based on what I know. I can tell you that if the colorcode is known at the point you want to display the colorname then you can do the lookup there. If not then the lookup would have to be done elsewhere and stored in a variable or session variable depending on where it is used.

    Hi DM... tanks again for your reply... not quite sure how to do as you suggested in terms of syntax. But I have written this bit of code into the same script where I modify the Category name and it works just well.... The code below does read the databse but it displays what was there and not what it has now been replaced with. Is there something I have forgotten to do here ??

    Code:
    <%
    Dim NewColor
    Dim LinkColorRS
    Set LinkColorRS = Server.CreateObject("ADODB.Recordset")
    	LinkColorRS.Open "SELECT *  FROM LinkColor", Connect, 3, 3
    While (Not LinkColorRS.EOF)
        Response.Write "<option STYLE='color: " & LinkColorRS("ColorCode") & " !important' value='" & LinkColorRS("ColorCode") & "'"
    	
    If (CategoryRS("TypeColor") = LinkColorRS("ColorCode")) Then Session("NewColor")=LinkColorRS("ColorName")	
    	
    If (CategoryRS("TypeColor") = LinkColorRS("ColorCode")) Then Response.Write "selected"
    	Response.Write">" & LinkColorRS("ColorName") & "</option>"
    	LinkColorRS.MoveNext
    Wend
    	LinkColorRS.Close()
    	CategoryRS.Close()
    								%>
    Or am I simply putting it into the wrong place within the script to drag out the new information similar to the way I did with the category name change ???
    Regards DA

  5. #80
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,786

    Re: VB Script will not remove modified data from Database

    That code is getting the value of the selected color which is what i thought you were talking about at one point but of course that is at the time the page is displayed not after you make a change to it. Apparently you want to show that changed value and to do that you need to know what it was changed to. From what you have said in previous posts apparently after the change you have the colorcode that it was changed to and are able to display that on the screen.

    Now think about that for a minute. You have the colorcode and are able to display it. You want the matching colorname and want to display that as well.
    I showed you how to get the colorname from the database that matches the color code. Where do you think you should put it?

    As for the syntax I showed you the syntax already more than once just look at it and give it a try. The fieldnames and/or table names in that sample line I gave you may need to be changed as I did not pay a lot of attention to your fieldnames but it definitely shoudl be enough to allow you to write a working select statement that will give you the data you need.

    If you do not understand something about that syntax or how to use the returned data then post a related question and we'll go from there.

    There is no point in posting the same section of code over and over that is not doing what you want nor even from the section that will be doing the display.
    Always use [code][/code] tags when posting code.

  6. #81
    Join Date
    Jun 2013
    Posts
    102

    Re: VB Script will not remove modified data from Database

    Quote Originally Posted by DataMiser View Post
    That code is getting the value of the selected color which is what i thought you were talking about at one point but of course that is at the time the page is displayed not after you make a change to it. Apparently you want to show that changed value and to do that you need to know what it was changed to. From what you have said in previous posts apparently after the change you have the colorcode that it was changed to and are able to display that on the screen.

    Now think about that for a minute. You have the colorcode and are able to display it. You want the matching colorname and want to display that as well.
    I showed you how to get the colorname from the database that matches the color code. Where do you think you should put it?

    As for the syntax I showed you the syntax already more than once just look at it and give it a try. The fieldnames and/or table names in that sample line I gave you may need to be changed as I did not pay a lot of attention to your fieldnames but it definitely shoudl be enough to allow you to write a working select statement that will give you the data you need.

    If you do not understand something about that syntax or how to use the returned data then post a related question and we'll go from there.

    There is no point in posting the same section of code over and over that is not doing what you want nor even from the section that will be doing the display.
    Hi DM and again, thanks for your patience. I have tried to display the link color but the best I have been able to do so far is to show the color but that result showed what the color was before it was changed and not after the change. I've passed a session var for the category name change from one script to another and it works great. I assumed that since I was able to build that into the category_edit script that I would be able to do exactly the same thing for the color change. I guess from what you are saying, I must be wrong so I will ponder about it for a little longer and havea look around to see how I post a related issue. :-)

  7. #82
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,786

    Re: VB Script will not remove modified data from Database

    Well if the Session var is populated when you show the edit page and you are assigning the color there then of course when you display it later it will show what it was when the page was loaded because that is what you told it to do. If that is not what you want then you have to do something different. You need to get the value after it is changed and to do that you need to lookup the value like I showed you and you have to do it in the script where you want to display it and after it is changed by the user could be before or after the DB is updated but you must have the value of the code after it has been selected.

    it really is not hard you just need to understand what you are trying to do and where you need to do it.
    Always use [code][/code] tags when posting code.

  8. #83
    Join Date
    Jun 2013
    Posts
    102

    Re: VB Script will not remove modified data from Database

    Quote Originally Posted by DataMiser View Post
    Well if the Session var is populated when you show the edit page and you are assigning the color there then of course when you display it later it will show what it was when the page was loaded because that is what you told it to do. If that is not what you want then you have to do something different. You need to get the value after it is changed and to do that you need to lookup the value like I showed you and you have to do it in the script where you want to display it and after it is changed by the user could be before or after the DB is updated but you must have the value of the code after it has been selected.

    it really is not hard you just need to understand what you are trying to do and where you need to do it.
    Thanks my friend. I've had enough of DIY for the day so will spend a few hours going over your comments and see if something goes 'click' like it did last time :-) DA

  9. #84
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,786

    Re: VB Script will not remove modified data from Database

    When you get a chance take a stab at it and then show the code where you are trying to get the colorname and where you are trying to display it and if they are in different scripts make sure to indicate to that effect and which script is which.
    Always use [code][/code] tags when posting code.

  10. #85
    Join Date
    Jun 2013
    Posts
    102

    Re: VB Script will not remove modified data from Database

    Quote Originally Posted by DataMiser View Post
    btw... this line ....
    Code:
    	If (TypeRS("TypeName") = TypeRS("TypeName")) Then Session("NewName")=TypeRS("TypeName")
    Why on earth did you write the If Test like that? You do know that TypeRS("TypeName") will always = TypeRS("TypeName") as it is the same thing and therefore must be the same so the test is totally useless.

    that line could be written
    Code:
    Session("NewName")=TypeRS("TypeName")
    And get the exact same result

    Hi DM.... I just noticed this little gem.... I guess the answer to that is I was uncertain as to what I could do so just talked myself through the code and sort of wrote what I said. It worked but by comparison to your way of expressing it, my effort was very inefficient. I've done exactly as you said and yes, it works fine :-) I'm still trying to find out how to post a related item but I have put into words exactly what I would like to do. By related do you mean a new thread ??

  11. #86
    Join Date
    Jun 2013
    Posts
    102

    Re: VB Script will not remove modified data from Database

    Quote Originally Posted by davida1956 View Post
    Hi DM.... I just noticed this little gem.... I guess the answer to that is I was uncertain as to what I could do so just talked myself through the code and sort of wrote what I said. It worked but by comparison to your way of expressing it, my effort was very inefficient. I've done exactly as you said and yes, it works fine :-) I'm still trying to find out how to post a related item but I have put into words exactly what I would like to do. By related do you mean a new thread ??
    One last attempt here before I look for the related issue link ..

    I need to select a value from my database which has two forms. One form is called LinkColor and the other form is called Type. I would like to display the value of TypeColor which is a text value in the Type form… #960 for example. The LinkColor table describes the colour in a field called ColorName. So if I read a value of #960 from the Type(TypeColor) the colour I expect to be displayed would be Brown the referenve value held in the LinkColor(ColorName) form. What is the correct way to query the database and can I store the result as a variable to call later on in the script in a response.write statement ?

  12. #87
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,786

    Re: VB Script will not remove modified data from Database

    You need to use a select statement like I showed you with a where clause so that the results are limited to what you want to get.

    When you say 2 forms I do not know if you mean to fields with the values or if you are talking about web forms or forms stored in a database. I assume that the use of the word form is not meant literally here but hard to be sure.

    Like I have said you need to have the colorcode available and then you can use that to do the lookup using a select statement like I showed you. Once you do that you can use that value to display on screen or place it in a variable and display it a few lines later. I still don't think you have showed the code where this display is to take place, mostly what has been showed is from a different script so it is very hard to try and give you anything more than general advice.

    The concept however is simple. Your code gets the colorcode value from the sumbitted form using the request method, it uses that value in the where clause of a select statement to get the matching colorname and then either displays that colorname value or assigns it to a variable and displays it a few lines down in the script, the where depends largely on how your script is formatted and what else is taking place in it.
    Always use [code][/code] tags when posting code.

  13. #88
    Join Date
    Jun 2013
    Posts
    102

    Re: VB Script will not remove modified data from Database

    Quote Originally Posted by DataMiser View Post
    You need to use a select statement like I showed you with a where clause so that the results are limited to what you want to get.

    When you say 2 forms I do not know if you mean to fields with the values or if you are talking about web forms or forms stored in a database. I assume that the use of the word form is not meant literally here but hard to be sure.

    Like I have said you need to have the colorcode available and then you can use that to do the lookup using a select statement like I showed you. Once you do that you can use that value to display on screen or place it in a variable and display it a few lines later. I still don't think you have showed the code where this display is to take place, mostly what has been showed is from a different script so it is very hard to try and give you anything more than general advice.

    The concept however is simple. Your code gets the colorcode value from the sumbitted form using the request method, it uses that value in the where clause of a select statement to get the matching colorname and then either displays that colorname value or assigns it to a variable and displays it a few lines down in the script, the where depends largely on how your script is formatted and what else is taking place in it.
    Hi Again... the new page I have made is very simple, apart from the menu bar and css style sheet there is only this bit of code....

    Code:
    <td align="center" valign="middle"><p class="textEvent">&nbsp;</p>
                            <p class="textEvent">The category name has now been changed to " 
                              <% Response.Write(Session("NewName"))%> 
                                " with the associated colour of &quot;<% Response.Write(Session("NewColor"))%>
                            &quot;.</p>
    which just displays the two new session variables. I think it is here that I will need to do the select statement. I'm not sure what to call elements in the database ? There are 3 sections or pages as I see them in the access database.. one called TYPE one called LINKCOLOR and one called EVENTS. each of these have fields in them. Perhaps this description will help ??

    I need to select a value from my database which has two 'Tables?'. One 'table'? is called LinkColor and the other table is called Type. I would like to display the value of TypeColor which is a text value in the Type 'table'?… #960 is an example. The LinkColor table describes the actual color in a field called ColorName so #960 would be assigned the value = Brown. The ColorCode field in LinkColor contains the same #960 value as the TypeColor. So if I read a value of #960 from the Type(TypeColor) the colour I expect to be displayed would be ColorName(Brown) from the reference value held in the LinkColor(ColorName) 'form'?. What is the correct way to query the database. I know I can store the result in a variable and display it later in the script.

    Perhaps you can advise what I should be calling these fields, forms or whatever. I wrote it last night to post on a related post. I really can understand you when you can't follow me, I guess you are used to guys who are more advanced than me and can identify things much more clearly, I'll get there :-)

  14. #89
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,786

    Re: VB Script will not remove modified data from Database

    Quote Originally Posted by davida1956 View Post
    Hi Again... the new page I have made is very simple, apart from the menu bar and css style sheet there is only this bit of code....

    Code:
    <td align="center" valign="middle"><p class="textEvent">*</p>
                            <p class="textEvent">The category name has now been changed to " 
                              <% Response.Write(Session("NewName"))%> 
                                " with the associated colour of "<% Response.Write(Session("NewColor"))%>
                            ".</p>
    which just displays the two new session variables. I think it is here that I will need to do the select statement.
    Yes you would need to do it just above that part so that you have the values when you want to display them.

    I'm not sure what to call elements in the database ? There are 3 sections or pages as I see them in the access database.. one called TYPE one called LINKCOLOR and one called EVENTS. each of these have fields in them. Perhaps this description will help ??
    Database > Tables > Fields

    Example: MasterInventory.Mdb would be a database. A database can hold several tables [as well as other things]
    MasterParts may be one of the tables and in that table you may have several fields like PartNumber, Description, Qty, Price and so on

    A Form is a GUI [the part the user sees on the screen to enter data or in the case of HTML it is everything inside the <Form> </Form> tags. It has nothing to do with storing data or data structure other than it is a means to guide the user entry.

    Your posts will be a lot less confusing if you use the proper terms.

    I need to select a value from my database which has two 'Tables?'. One 'table'? is called LinkColor and the other table is called Type. I would like to display the value of TypeColor which is a text value in the Type 'table'?… #960 is an example. The LinkColor table describes the actual color in a field called ColorName so #960 would be assigned the value = Brown. The ColorCode field in LinkColor contains the same #960 value as the TypeColor. So if I read a value of #960 from the Type(TypeColor) the colour I expect to be displayed would be ColorName(Brown) from the reference value held in the LinkColor(ColorName) 'form'?. What is the correct way to query the database. I know I can store the result in a variable and display it later in the script.
    For a lookup like this you use one table. That table should have both fields in it. If you do not have a table that has a colorcode and colorname [or whatever you are calling them] then you may have a problem. There has to be a way to know which code goes with with color.


    So the first thing you need to do is clarify what you are working with in terms of your data table that holds the colorname description or whatever it is called. Post the table name, fieldnames and indicate which field is for which data then I can give you a better idea.

    Also note that you do not really need a session var here but you can use it so long as you have the correct code in it. If that code is the one being set to the session var before the user makes a change then it will not give you want you need. You need the value of the code when the user submits the form [the value that you are actually writing to the database rather than the one that was there before.]
    Always use [code][/code] tags when posting code.

  15. #90
    Join Date
    Jun 2013
    Posts
    102

    Re: VB Script will not remove modified data from Database

    Quote Originally Posted by DataMiser View Post
    Yes you would need to do it just above that part so that you have the values when you want to display them.



    Database > Tables > Fields

    Example: MasterInventory.Mdb would be a database. A database can hold several tables [as well as other things]
    MasterParts may be one of the tables and in that table you may have several fields like PartNumber, Description, Qty, Price and so on

    A Form is a GUI [the part the user sees on the screen to enter data or in the case of HTML it is everything inside the <Form> </Form> tags. It has nothing to do with storing data or data structure other than it is a means to guide the user entry.

    Your posts will be a lot less confusing if you use the proper terms.



    For a lookup like this you use one table. That table should have both fields in it. If you do not have a table that has a colorcode and colorname [or whatever you are calling them] then you may have a problem. There has to be a way to know which code goes with with color.


    So the first thing you need to do is clarify what you are working with in terms of your data table that holds the colorname description or whatever it is called. Post the table name, fieldnames and indicate which field is for which data then I can give you a better idea.

    Also note that you do not really need a session var here but you can use it so long as you have the correct code in it. If that code is the one being set to the session var before the user makes a change then it will not give you want you need. You need the value of the code when the user submits the form [the value that you are actually writing to the database rather than the one that was there before.]

    I think singing from the same hymn sheet would be a great place to start, perhaps it will make like that much easier. I don’t think that the data I want to extract has all the information in the same place so it may be a problem You asked me to post the DB information so you can explain what is a field or form or tab ets andit is a bit long winded but it shows I understand how things work but not How to make things work…Ok… here goes…. I have an Access database called Calendar.mdb and when I open it I can see 4 tabs…

    Events LinkColor Type Users

    Each of these 4 Tabs have fields within them so when I open USERS
    I can see 3 fields. Username, Password and Admin Rights. This works perfectly

    When I open Events I see…

    15 fields, one is called EventID which is a unique numeric field to identify Each Event entry and is followed by 14 other fields called EVENTDATED1 through to VENTDATED14. The third field is called Event Type which has a numeric value which and is associated with each of the 4 Categories I currently have............. So I see the 4 main fields which are

    EventName = A text field with…Holiday (For instance)
    EventDated= 10/10/2013, 11.10/2013 repeat for 14 days
    EventType=966 (Relates to each of the 4 categories (referenced in Type as well) I use. Booked, Enquired, Reserved or Changed)
    Event Description= Another text field ( I am on holiday or I have a meeting etc.)
    there are others that deal with smaller issues such as

    Event Approved ...........(a simple Y or N)
    Event Location which is a text field.............. (In the Boardroom for example) and
    Event Description ................another text field (Meeting about business direction for example)
    This part of the DB also works perfectly thanks to a little help from you very early on.

    The next tab is called LinkColor inside there I have 3 fields which are

    ID ColorName ColorCode

    ID is a text field that relates to the number of colors available to choose from currently 6
    ColorName......... holds the Textual name of the colour and ties in with the ID so.. 1 = Black… 2=Red etc
    ColorCode........ is also a text field (and this is confusing) which contains the text representing a color but it is the hex value of that color which is used in the next tab

    So if I want to put it into order I see 1 Black #000
    2 Red #F00

    The last tab is called Type and this is where I have problems tying it to LinkColor.
    This has 3 fields called

    TypeID This is a text field which holds the number 966 (same as in the value in Events)
    TypeName This is a text field and holds the same value as EventName in the Events tab.
    TypeColor This is a text field and holds…. The text value of the color association but in hex form which is used in the LinkColor tab.

    So I see 966 Holiday #00

    The process is
    1 Choose a name = Enquiry
    2 Choose a colur for it = 1 = #000 = Black .... 2 = #F00 = Red and so on for 6 colors
    3 Select dates you need = 08/11/2013..up to 2 weeks duration
    4 Add a Location = In the Boardroom
    5 Add details = Discussion about next year’s finances... etc.
    6 Event Approved = Y or N
    7 Edit or Delete = This is the bit that I can’t grasp……………

    This populate the complete record for a single record with multiple day events. All of the information is input to the database through a GUI screen form. I bet I am your worst nightmare !!! Look forward to your reply :-) DA

Page 6 of 8 FirstFirst ... 345678 LastLast

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center