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 21st, 2004, 04:31 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
Default delete records in database

Hello I have to delete the records in a SQL server. For that please refer to my code. You will understand what I am doing. When I hit img. It gives me confirm message. Do you want to delete. I say no. It doesnot delete when I say yes. The values in text boxes remains unchanged. Can you please modify the code? Thanks your reponse will be appreciated.
  <%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>"
     strGrid =strGrid+ " <TD ><img type =""button"" name=btnDelete src ='../images/xDel1.gif' onclick=""javascript:deleteConfirm();""></TD></TR>"
 end if

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)
%>
<script language = javascript>
    function deleteConfirm() {
      if (confirm("You are about to " +
           "delete a record into the database." +
           "Click ok to continue or Cancel to abort.")){
             return true; }
      else {
             alert("Record not deleted")
              return false;}

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



 
Old October 21st, 2004, 06:20 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Why is that you are using INPUT boxes when you want to delete records? By doing that you are complicating the operation.

Also I don't see you execute DELETE statement anywhere in your code.

Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old October 22nd, 2004, 07:52 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How will I modify the code?

 
Old October 24th, 2004, 07:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Shoakat,

Not sure, if I can give you the entire code. But I can show you how to go about that.
Code:
Do while not objHistoryRate.EOF
   
    dateFrom =cstr(convNull (objHistoryRate("dtRateFrom")))
    dateUntil=cstr(convNull (objHistoryRate("dtRateTo")))
    HourlyRate=cstr(convNull(objHistoryRate("decHourlyRate")))

    ' Display the data that are required in rows within a HTML table.
    ' Use a check box for each ROW, may be in the first column of the table.
    ' All check boxes should have the same name.
    ' And each checkbox should have its corresponding RowId/RecordId as its value

    objHistoryRate.MoveNext()
loop
' Use a submit button that shows DELETE as its value.
' Let the user select the row to be deleted using the check box/row
' On click of Delete show a confirmation, if yes submit the form else don't.
' On submission, Request for checkbox value, that comes as comma separated value.
' This can be used within the delete sql statement using IN operator to delete the rows that are selected.
You can try to code with this logic. Always you can come back here for help if you are stuck up somewhere with some error.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old October 25th, 2004, 08:23 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I dont have to use the check Box. I have to use an arrow corresponding to each row that when i click asks the user whether he should delete the corresponding row. If yes it should delete the corresponding row.
I believe arrays are required to solve this problem. If you can see my code. You will realize where to modify


 
Old October 25th, 2004, 08:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Shoakat,

This way as you mentioned in your previous post, you could let the user delete just one row at a time, suppose if the user wishes to delete 5 consecutive rows, he has to click 5 times on each of those ARROW which you provide for delete. Instead in the other post which I had posted the logic, it would let you select multiple rows at a time per page and on one click it would delete all the selected rows. Not decision is yours, to go with whichever you prefer. And you can code it to that effect. You can try coding on that, and post here always to get any help if you are stuck up in the middle with some errors.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old October 25th, 2004, 11:51 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually in my assignment. I have to limit the user to delete a single row at a time. My update also
doesnot work. When the user changes number. In data base there is no update. Suppose the user
updates the record in the middle.In database it only gives the value of the last text box. I I change the
value of the last text box. It update all the text box to that value. Please help me as I assignment
is due tomorrow

 
Old October 25th, 2004, 09:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

You will have to provide backend details for the same, like what is the primary key field on that table. Does it submit the form details onclick of any delete button? If not it should. I still don't see any necessity for using INPUT boxes, when you have to delete the records. Is that you are using the same page for Insert/Update/Delete operations?

Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old October 26th, 2004, 07:51 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes I am using the same page for update,delete,and add. Try to look at the code. You will
understand what am I doing. As I told you earlier, my assignment is due today. I will appreciate
your reply earnest.

 
Old October 26th, 2004, 08:31 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

But you haven't mentioned about the table structure and primary key field if any.

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to delete all the records in a table Kai Lai Access VBA 2 March 15th, 2016 07:20 AM
Add/Update/Delete Database records MANUALLY jn148 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 December 14th, 2008 10:18 AM
delete null records stealthdevil Access VBA 3 January 23rd, 2007 04:48 PM
Delete Duplicate Records prasanta2expert SQL Server 2000 9 December 15th, 2006 10:44 PM
How to delete the dataset records jabby ADO.NET 18 August 1st, 2004 11:42 PM





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