Why does the the program not quit in this case?

B

Bob

Hi,

If the test is true, the message 'not available' must be shown and quit the
program.
But when the test is true and when table 'data2' is empty (so nrg=0), i get
the error:"dividing by zero". Why? The program should quit, no?

Thanks
Bob

the code:
.....
x= Date.Now
sql = "select begindate from mydate"
comd = New OleDbCommand(sql, oConnection)
dtreader = comd.ExecuteReader
dtreader.Read()
If x <= dtreader.GetDateTime(0) Then 'compare today with date
in table
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(),
"myscript", _
" alert(not available);" & _
" window.location.href='http://www..../';", True)
End If
' should stop here if test is true
dim z, nrg as integer
sql = "select count(*) from data2 ;"
comd = New OleDbCommand(sql, oConnection)
nvrg = comd.ExecuteScalar
z=10/nrg
.....
 
P

pamelafluente

Hi B

you did not put any Exit sub / function
or similar, why do you expect it does not continue after the End if ?

-P

Bob ha scritto:
 
M

Marina Levit [MVP]

That is not the command being executed.

The command being executed is to write that string out to the response
stream. Then it keeps going.

Once the page is done processing, the response stream will be sent to the
browser. The browser will then render the HTML and execute any scripts.

There is a big disconnect between the server and the client. Client side
code does not execute until the browser receives the response stream. But
that doesn't happen until the page is done processing and the response gets
to the browser.
 
C

Cor Ligthert [MVP]

Bop,

Put in top of your code page
"Option Strict On" than you will see many errors which are now not seen.

Your dividing by zero will probably be if the connection does not exist.
However without that Option Strict On the behaviour is mostly not real good
predictable.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top