Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 April 1st, 2008, 10:01 AM
Authorized User
 
Join Date: Jan 2004
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I removed the "Order By" from the SQL statement.
The error relates to any record value that is being passed to the first SQL statement. i.e. "Incorrect syntax near Division Code'. The Division Code to be deleted and those that ought not be deleted.

On the web page the line that indicated *blow up here, is where the browser has highlighted the line of code.

If the record is in the ATTDivision table but not in ATTEmployee, then I need to delete that record otherwise notify the user that the deletion can not take place.


 
Old April 1st, 2008, 10:41 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ok. Count() is a SQL Aggregate function, it will count the number or rows for the specified column:

"SELECT Count(ATTDivision.DivisionCode) " & _
                          "FROM ATTDivision INNER JOIN " & _
                           "ATTEmployee ON ATTDivision.DivisionCode = ATTEmployee.DivisionCode " & _
                          "WHERE (ATTDivision.DivisionCode = '" & DivisionCode2.Text & " ') ")

So if the count statement here returns 0 it means that your query is returning 0 records.

Next you call the scalar value
Dim recordbedeleted As Boolean = (Convert.ToInt32(cmd.ExecuteScalar) = 0) Now I *assume* you are wanting to delete records from the table if there are no rows returned by your first query so if the scalar returns 0 recordbedeleted will become true otherwise false.

My suggestion is that if you are not getting the results you are expecting first test your SQL to verify what you *think* is coming back is actually the data that is coming back.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old April 1st, 2008, 10:47 AM
Authorized User
 
Join Date: Jan 2004
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Great!.
You understand completely, now I will test the first sql statement and hopefully 0 count will come back, at which time I again, hopefully, will be able to correctly delete the record.

 
Old April 1st, 2008, 11:04 AM
Authorized User
 
Join Date: Jan 2004
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
Default

HI,

Getting closer to the end and getting panicky, as I need to present in 1 1/2 hour.
The error was an extra "(" after the WHERE and before "ATTDivision").

Now that has been corrected, it does not stop processing. the correct record gets deleted as well as the incorrect record.

The 'Return' statement is in place.
If (Not ClientScript.IsStartupScriptRegistered("clientScri pt")) Then
                        ClientScript.RegisterClientScriptBlock(Me.GetType( ), "clientScript", strScript)
                        Return
                    End If


 
Old April 1st, 2008, 11:32 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

The DELETE statement only fires when the boolean value is true so the Return statement will NEVER fire because the else clause is never evaluated. I should also point out that using Return is a moot point because you are in an else clause where no database transactions take place. The else statement should be allowed to execute entirely.

If you are deleting incorrect records I imagine your WHERE clause of your delete statement is incorrect.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
opening a webpage in a new window riyadsmail ASP.NET 1.0 and 1.1 Basics 3 August 31st, 2007 06:56 AM
opening a new window rgpassey Javascript How-To 2 September 14th, 2005 11:38 AM
Opening New Window p_nut33 Classic ASP Basics 1 August 6th, 2004 08:11 PM
Close Parent window on opening child window pkdev Javascript How-To 8 April 11th, 2004 12:06 PM
Opening New Window james_sellwood ASP.NET 1.0 and 1.1 Basics 5 June 12th, 2003 11:43 AM





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