Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 23rd, 2004, 02:10 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
Default updating error

Hello Guys, I have an updating question. When I hit button called "new" three text boxes appear in a single row. When the user enters date and number data types say 9/11/2004. 9/11/2006 and 15. And if the user updates the previous records which are in Array. Like he changes date to 9/10/2004, 9/11/2005 and 30 from 9/15/2005 and
15. Three are a lot of records from the the old records. Know what happens everything is changed to the last text boxes records if the user tries to update the other ones except the record which is at the top. When the user hits save butoon. every data type is and number is changed exactly to the one which is at the last of an array.Everythin g is updated execpt the last one. Please give suggestion and modify the code.
  Dim rsStrUpdate
if Request.Form("txtMode")="S" then
  objHistoryRate.requery
  if not objHistoryRate.EOF then
    index = 1
    Do while not objHistoryRate.EOF
    'old values
     dateFrom = cstr(convNull(objHistoryRate("dtRateFrom")))
     dateUntil = cstr(convNull(objHistoryRate("dtRateTo")))
     HourlyRate= cstr(convNull(objHistoryRate("decHourlyRate")))

    'new values
    if Request.Form("txtdateFrom").Count > 0 then
        'Response.Write index
        ndateFrom = Request.Form("txtdateFrom")(index)
        ndateUntil = Request.Form("txtdateUntil")(index)
        nHourlyRate = Request.Form("txtHourlyRate")(index)
    else
        ndateFrom = ""
        ndateUntil = ""
        nHourlyRate = ""
    end if

     'update record with changes only
     if dateFrom <> ndateFrom or dateUntil <> ndateUntil or HourlyRate <> nHourlyRate then
     'update this record
     'make sure that variables are all string
     if ndateFrom ="" then
        ndateFrom = "null"
     else
        ndateFrom = "'" + ndateFrom + "'"
     end if

    if ndateUntil ="" then
        ndateUntil = "null"
    else
        ndateUntil = "'" + ndateUntil + "'"
    end if

    if nHourlyRate ="" then
        nHourlyRate = "null"
    else
        nHourlyRate = nHourlyRate
    end if

       strUpdate = "update tblCustRate set dtRateFrom =" &ndateFrom&_
                ",dtRateTo =" & ndateUntil &_
                ",decHourlyRate=" & nHourlyRate &_
                "where iEmpID =" & iEmpID &_
                "and iTaskiD=" & iTaskID &_
                "and iProjDetiD=" & iProjDetID


      set rsStrUpdate =server.CreateObject("ADODB.Recordset")
      rsStrUpdate.ActiveConnection = objConn
      'Response.Write "<br>loop " + cstr(index) + ":<br>"
      'Response.Write strUpdate
      rsStrUpdate.Open strUpdate
     end if
     index=index+1
     objHistoryRate.MoveNext()
     loop
   end if
  '
   '''''''''''''''''''''''''''''''''''''''''''''
  'insert new rec
 numAdd =1
 addFld =0
  Do while addFld < numAdd
    if Request.Form("AtxtdateFrom")<>"" and Request.Form("AtxtHourlyRate")<>"" then
        'Response.Write "New Record to be Inserted"
        ndateFrom = (Request.Form("AtxtdateFrom"))
        ndateUntil = (Request.Form("AtxtdateUntil"))
        nHourlyRate = (Request.Form("AtxtHourlyRate"))

        if resType="E" then
            strEmpID = cstr(iEmpID)
            strSubID = "null"
        else
            strEmpID = "null"
            strSubID = cstr(iSubcontID)
        end if

        if ndateFrom ="" then
            ndateFrom = "null"
        else
            ndateFrom = "'" + ndateFrom + "'"
        end if

        if ndateUntil ="" then
            ndateUntil = "null"
        else
            ndateUntil = "'" + ndateUntil + "'"
        end if

        if nHourlyRate ="" then
            nHourlyRate = "null"
        else
           nHourlyRate = nHourlyRate
        end if
        'add record here
        atTable = "tblCustRate"
        atfldList = "(iEmpID, iSubcontID,iTaskID," + _
                "dtRateFrom, dtRateTo, decHourlyRate, iProjDetID) "
        atvalList = "(" + strEmpID + "," + strSubID + ","+ cstr(iTaskID) + "," + _
                ndateFrom + ","+ ndateUntil + "," + nHourlyRate + "," + cstr(iProjDetID) + ")"
         'pass the parameter and execute command to insert project and recordset will return the iProjectID.
        'Response.Write "The parameters to be passed to sp_InsertStmt: <br>"
        'Response.Write "atTable:"+ atTable + "<br>"
        'Response.Write "atfldList:" + atfldList + "<br>"
        'Response.Write "atvalList:" + atvalList + "<br>"
        'Response.End
        set cmdObj = server.CreateObject("ADODB.Command")
        cmdObj.ActiveConnection = objConn
        cmdObj.CommandTimeout = Application("HR2000Conn_CommandTimeout")
        cmdObj.CommandType = 4
        cmdObj.CommandText = "sp_InsertStmt"
        set param1 = cmdObj.CreateParameter("@table", 200, 1, 50)
        set param2 = cmdObj.CreateParameter("@fldList", 200, 1, 2000)
        set param3 = cmdObj.CreateParameter("@valList", 200, 1, 2000)
        cmdObj.Parameters.Append(param1)
        cmdObj.Parameters.Append(param2)
        cmdObj.Parameters.Append(param3)
        param1.value = atTable
        param2.value = atfldList
        param3.value = atvalList
        set rsUpdate = server.CreateObject("ADODB.Recordset")
        rsUpdate.ActiveConnection = objConn

        set rsUpdate = cmdObj.Execute()
        rsUpdate.Close
        set rsUpdate = nothing
        set cmdObj = nothing
     end if
     addFld = addFld+1
loop
objHistoryRate.Requery
 end if



strGrid= "<table border=1><tr>"

 if Request.Form("txtMode")="A" then
     strGrid =strGrid+ " <TD><INPUT type=""text"" size=15 id=AtxtdateFrom name=AtxtdateFrom ></TD>"
     strGrid =strGrid+ " <TD><INPUT type=""text"" size=15 id=AtxtdateUntil name=AtxtdateUntil ></TD>"
     strGrid =strGrid+ " <TD><INPUT type=""text"" size=15 id=AtxtHourlyRate name=AtxtHourlyRate ></TD></TR>"
     'strGrid =strGrid+ " <TD ><img type =""button"" name=btnDelete src ='images/xDel1.gif' onclick=""javascript:deleteConfirm();""></TD></TR>"
 end if
 objHistoryRate.Requery

Do while not objHistoryRate.EOF

    dateFrom =cstr(convNull (objHistoryRate("dtRateFrom")))
    dateUntil=cstr(convNull (objHistoryRate("dtRateTo")))
    HourlyRate=cstr(convNull(objHistoryRate("decHourly Rate")))

    strGrid =strGrid+ " <TD><INPUT type=""text"" size=15 id=txtdateFrom name=txtdateFrom value='"+ dateFrom +" ' ></TD>"
    strGrid =strGrid+ " <TD><INPUT type=""text"" size=15 id=txtdateUntil name=txtdateUntil value='"+ dateUntil+" '></TD>"
    strGrid =strGrid+ " <TD><INPUT type=""text"" size=15 id=txtHourlyRate name=txtHourlyRate value='"+HourlyRate+" '></TD>"
    strGrid =strGrid+ " <TD ><img type =""button"" name=btnDelete src ='images/xDel1.gif' onclick=""javascript:deleteConfirm();""></TD></TR>"
    objHistoryRate.MoveNext()

loop
strGrid = strGrid + "</Tr></TABLE>"
Response.Write(strGrid)
Response.Write "</TR>"

function convNull(str)
 if isNull(str) then
    convNull = ""
 else
    convNull = str
 end if
end function


%>


<script language = javascript>
 function callAdd(){

  document.thisForm.submit();

 }
</script>

<script language = javascript>
 function validateDate(){
    try{
            document.thisForm.submit();
       return true;
          }
   catch(exception){}
 }

</script>

<script language = javascript>
 function deleteConfirm() {
  var Msg="DO you want to Delete the record";
   if (confirm(Msg)){
   var val1=document.thisForm.txtdateFrom.value;
   var val2=document.thisForm.txtdateUntil.value;
   var val3=document.thisForm.txtHourlyRate.value;
       return true; }
  else {
       alert("Record not deleted")
          return false;}

    document.thisForm.submit();
}
  </script>
 <%

    'Delete Records
'if Request.Form("txtMode")="A" and 1=2 then
  if Request.Form("txtMode")="T" then
    strDel = "delete * from tblCustRate" &_
            "where iEmpID =" & iEmpID &_
            "and iTaskiD=" & iTaskID&_
            "and iProjDetiD=" & iProjDetID&_
            " and dtRateFrom=" &val1&_
            " and dtRateTo=" &val2&_
            " and decHourlyRate=" &val3

  set rsStrDelete =server.CreateObject("ADODB.Recordset")
  rsStrDelete.ActiveConnection = objConn
  rsStrDelete.Open strDel
  end if

    %>

 <input type = "button" name = "btnNew" value = "new" onclick="javascript:thisForm.txtMode.value='A';cal lAdd();">
 <Input type = "hidden" name = "txtMode" value ="T">
 <input type = "button" value = "save" onclick="javascript:thisForm.txtMode.value='S';val idateDate();" name= btnSave>


 
Old October 24th, 2004, 05:26 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I am very sorry, but I have *no* idea what you're talking about.
(It could be that my hangover is playing tricks with me, but still...).

Can you please describe the problem in more detail. And if you do, can you limit the code you're posting to the relevant sections (if possible)?

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Zij Gelooft In Mij by André Hazes (Track 6 from the album: Al 15 Jaar Gewoon André - CD1) What's This?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error on updating the date field surya MySQL 2 September 16th, 2008 11:56 PM
Updating query using inner join sintax error gfranco Access 0 April 18th, 2008 10:08 PM
DetailsView "Out of range" error when updating rsearing ASP.NET 2.0 Basics 16 August 17th, 2007 07:38 AM
Error 800a0cb3 when Updating charlix SQL Server ASP 2 January 28th, 2004 01:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.