473,320 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Abort an operation

Does anyone have some good advice for the following situation?

If a condition is true, an insert is restricted ( aborted ) otherwise
the insert is allowed. I have been killing myself on this for a week
with no success. I just need some advise at this point. Currently I
am running a stored proc that returns yes or no based on the variables
that a user is inputting. If the sp result is yes ( a record already
exists ) the insert isnt allowed and the user is forced to update the
existing record.

I am not much of a coder yet ( still learning ) and dreamweaver code is
confusing me!!!!

Jan 15 '07 #1
12 1966
Mangler wrote:
If a condition is true, an insert is restricted ( aborted ) otherwise
the insert is allowed. I have been killing myself on this for a week
with no success. I just need some advise at this point. Currently I
am running a stored proc that returns yes or no based on the variables
that a user is inputting. If the sp result is yes ( a record already
exists ) the insert isnt allowed and the user is forced to update the
existing record.
I often use Add/Update procedures for this type of thing -- that is, one
procedure that can do either. You can structure them in several ways. Here
is the simplest form:

IF EXISTS (SELECT * FROM myTable WHERE ...) BEGIN
UPDATE ...
END
ELSE BEGIN
INSERT ...
END

Depending on your DB constraints, you can do it this way, too:

IF NOT EXISTS (SELECT ...) BEGIN
INSERT ... -- new record, empty except for key
END

UPDATE ... -- unconditionally

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Jan 15 '07 #2

Dave Anderson wrote:
I often use Add/Update procedures for this type of thing -- that is, one
procedure that can do either. You can structure them in several ways. Here
is the simplest form:

IF EXISTS (SELECT * FROM myTable WHERE ...) BEGIN
UPDATE ...
END
ELSE BEGIN
INSERT ...
END

Depending on your DB constraints, you can do it this way, too:

IF NOT EXISTS (SELECT ...) BEGIN
INSERT ... -- new record, empty except for key
END

UPDATE ... -- unconditionally

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.

I can see where that goes....I just have to figure out all of the
syntax and what not but thanks for the idea.

Quick question if you dont mind. In my existing page, I have
everything working except the abort edit script. I was told that it
doesnt matter where in the code you put that script. I find that hard
to believe because when I place it anywhere other that where it is now,
everything doesnt work, including the SP. But when I put it in the
place its at now, all inserts are aborted. This has me confued, do you
have any insight on why this is happening?

Jan 15 '07 #3
Mangler wrote:
In my existing page, I have everything working except the
abort edit script. I was told that it doesnt matter where
in the code you put that script. I find that hard to believe
because when I place it anywhere other that where it is now,
everything doesnt work, including the SP. But when I put it
in the place its at now, all inserts are aborted. This has
me confued, do you have any insight on why this is happening?
Without seeing what you are doing, there is no way to guess. Can you provide
a little bit of code to highlight the issue?


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Jan 15 '07 #4

Dave Anderson wrote:
>
Without seeing what you are doing, there is no way to guess. Can you provide
a little bit of code to highlight the issue?

--
Dave Anderson
Again, sorry about the dreamweaver code......

<CODE>

If (MM_i <LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues
& ") values (" & MM_dbValues & ")"
If spDupresult = "YES" Then '********************Problem Area
MM_abortEdit = true '********************If I put this
here, all inserts are aborted but everything else
'********************works
fine, if I move it; everything goes nuts
If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <"") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
End If

</CODE>

Jan 15 '07 #5

"Mangler" <dw******@directwireless.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
>
Dave Anderson wrote:
>>
Without seeing what you are doing, there is no way to guess. Can you
provide
a little bit of code to highlight the issue?

--
Dave Anderson

Again, sorry about the dreamweaver code......

<CODE>

If (MM_i <LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues
& ") values (" & MM_dbValues & ")"
If spDupresult = "YES" Then '********************Problem Area
MM_abortEdit = true '********************If I put this
here, all inserts are aborted but everything else
'********************works
fine, if I move it; everything goes nuts
If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <"") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
End If

</CODE>
That would rather suggest that MM_abortEdit is always false. Have you done
a Response.write MM_AbortEdit to check its value ? And/Or a Response.Write
for spDupresult to check its value? And have you found the Find-and-Replace
thingy in Dreamweaver that allows you to select the current folder and
replace all the instances of MM_ with ""? :-)

--
Mike Brind
Jan 15 '07 #6

Mike Brind wrote:

That would rather suggest that MM_abortEdit is always false. Have you done
a Response.write MM_AbortEdit to check its value ? And/Or a Response.Write
for spDupresult to check its value?
Yes, that is how I confirmed spDupresult is working

<% IF (spDupresult) = "YES" Then Response.Write("The requested insert
has been denied. A record already exsists, please scroll down and
update the respective part.") END IF %>

As for MM_AbortEdit- like you said, always seems to stay false.
And have you found the Find-and-Replace
thingy in Dreamweaver that allows you to select the current folder and
replace all the instances of MM_ with ""? :-)
No, looking now......

I a lost as to how to get this last part working. Very frustrated :(

Jan 15 '07 #7
Mangler wrote:
If spDupresult = "YES" Then '********************Problem Area
MM_abortEdit = true '********************If I put this
here, all inserts are aborted but everything else
'********************works
fine, if I move it; everything goes nuts
If (Not MM_abortEdit) Then
Why are you assuming (Not MM_abortEdit) is true in the absence of assigning
a value to MM_abortEdit? Remember, (Not Null) is (Null), and not (True):
http://msdn.microsoft.com/library/en...f2675227d3.asp

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Jan 16 '07 #8

Dave Anderson wrote:
Why are you assuming (Not MM_abortEdit) is true in the absence of assigning
a value to MM_abortEdit? Remember, (Not Null) is (Null), and not (True):
http://msdn.microsoft.com/library/en...f2675227d3.asp
Thats easy... inexperience! But, because of people like you ( who set
me straight ) I am learning. I will re-look at the code with my new
found knowlege and see what happens.

Thanks....

Respectfully,

Danny

Jan 17 '07 #9

Hi guys,

Still not having luck here......
With the understanding that false = true and true = false I have this:

If spDupresult = "YES" Then
MM_abortEdit = false
Else

If MM_abortEdit = true Then
' execute the insert
Got any more suggestions?

Respectfully,
Danny

Jan 17 '07 #10
Mangler wrote:
Still not having luck here......
With the understanding that false = true and true = false I have this:

If spDupresult = "YES" Then
MM_abortEdit = false
Else

If MM_abortEdit = true Then
' execute the insert
Got any more suggestions?
I'm not sure you saw my point. In your example, you never show what
the initial value of MM_abortEdit is. If it is Null, then consider the
following:

Sub WrongWay(spDupresult)
Dim MM_abortEdit
MM_abortEdit = Null
If spDupresult = "YES" Then MM_abortEdit = True
Response.Write(MM_abortEdit & ":" & Not MM_abortEdit)
If MM_abortEdit Then Response.Write(":Yes")
If Not MM_abortEdit Then Response.Write(":No")
Sub

Sub RightWay(spDupresult)
Dim MM_abortEdit
If spDupresult = "YES" Then
MM_abortEdit = True
Else
MM_abortEdit = False
End If
Response.Write(MM_abortEdit & ":" & Not MM_abortEdit)
If MM_abortEdit Then Response.Write(":Yes")
If Not MM_abortEdit Then Response.Write(":No")
Sub

Call WrongWay("YES") ' True:False:Yes
Call WrongWay("NO") ' :
Call RightWay("YES") ' True:False:Yes
Call RightWay("NO") ' False:True:No

As you can see, your code example "fits" the WrongWay model. You assigned
one possible boolean value (True), but then tested for (Not False), never
considering that there might be a (Not Null) alternative that does nothing.

It is worth asking why you don't simply use the inequality operator directly
and skip the extra variable:

If spDupresult <"YES" Then
' execute the insert
...
End If

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Jan 18 '07 #11

"Mangler" <dw******@aspdevil.comwrote in message
news:11**********************@38g2000cwa.googlegro ups.com...
>
Hi guys,

Still not having luck here......
With the understanding that false = true and true = false I have this:

If spDupresult = "YES" Then
MM_abortEdit = false
Else

If MM_abortEdit = true Then
' execute the insert
Got any more suggestions?
Only the same one as before: use Response.Write to test the value of all the
variables as you go through the code. It is an invaluable way to catch
logical errors.

Also, as Dave pointed out, an uninitialised variable will be null or empty.
You should set a default value for MM_abortEdit, which in your case is true.

Actually, as Dave also pointed out in his latest post, If spDupresult <>
"YES" Then 'execute the insert will bypass the additional unnecessary
MM_abortEdit variable.

--
Mike Brind
Jan 18 '07 #12
Thanks guys, its working now. Appreciate the help.

Jan 18 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Lothar Scholz | last post by:
Hello, i use the ftplib to do some tasks and my GUI offers an "Abort" button to stop but unfortunately there is no general way to stop the ftp asynchronously from another thread. Is it possible...
11
by: Keith Langer | last post by:
I have an application which consists of a main work thread and multiple threads which each maintain a TCP socket. When a configuration change occurs, all activity on the socket threads must be...
4
by: Jeff | last post by:
I am running a worker thread that manipulates some hardware setting every so often. My problem is that the hardware manipulation cannot be interrupted once it has started How can I ensure that...
7
by: Morris | last post by:
I want to abort a running thread, so I call MyThread.abort() function. My problem is this thread runs "almost" like a while(true) loop and I don't want the Abort() function interrupts the thread at...
20
by: Doug Thews | last post by:
I ran into an interesting re-pain delay after calling the Abort() method on a thread, but it only happens the very first time I call it. Every time afterward, there is no delay. I've got a...
13
by: Andy Fish | last post by:
Hi, I am using COM interop to invoke MS word from my .net app. If word pops up a dialog box, my thread obviously hangs until the dialog is answered. Here's the problem: because the app is...
4
by: am | last post by:
Hi to all. I have a little problem. I'm working with threads, and I need to abort or suspend them, but many experts dissuade from use Thread.Abort and Thread.Suspend. As I didn't find other way,...
3
by: steve | last post by:
Hi All I have a VB.net 2005 app which uses MS Report Viewer to create reports Occassionally I get the following error when changing to a different report User code running on thread 196 has...
1
by: masaniparesh | last post by:
Hi, In my C# program i am termination thread by thread.Abort when times out occur. But i figured out that even after thread.Abort operation the thread is being alive for the random time. I have...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.