Hello group,
In my apps I connection to SQL database.
try
{
//connect to db
}
catch
{
MessageBox("Error Connect. Close Apps?","Sql
Error",MessageBoxButtons.OKCancel,MessageBoxIcon.E rror);
}
When db is connection error apps show messagebox with button OK and Cancel.
My question: How close this application after OK, and continuue apps after
Cancel?
catch
{
MessageBox("Error Connect","Sql
Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
Close();
}
Not work.
Thx PawelR 4 10049
Hello,
In my apps this code is before
InitializeComponent();
In article <MP************************@news.tpi.pl>, pa************@poczta.onet.pl says... Hello group, In my apps I connection to SQL database. try { //connect to db } catch { MessageBox("Error Connect. Close Apps?","Sql Error",MessageBoxButtons.OKCancel,MessageBoxIcon.E rror);
} When db is connection error apps show messagebox with button OK and Cancel. My question: How close this application after OK, and continuue apps after Cancel?
catch { MessageBox("Error Connect","Sql Error",MessageBoxButtons.OK,MessageBoxIcon.Error); Close(); } Not work.
Thx PawelR
hi Pawel
use the dialogresult object
DialogResult dlr = (Messagebox.Show("blablabla",
MessageBoxButtons.OkCancel)
if (dlr == DialogResult.Ok)
{
close();
}
else
{
do...;
}
"PawelR" <pa************@poczta.onet.pl> wrote in message
news:MP************************@news.tpi.pl... Hello group, In my apps I connection to SQL database. try { //connect to db } catch { MessageBox("Error Connect. Close Apps?","Sql Error",MessageBoxButtons.OKCancel,MessageBoxIcon.E rror);
} When db is connection error apps show messagebox with button OK and
Cancel. My question: How close this application after OK, and continuue apps after Cancel?
catch { MessageBox("Error Connect","Sql Error",MessageBoxButtons.OK,MessageBoxIcon.Error); Close(); } Not work.
Thx PawelR
PawelR,
I think that what you want is the static Quit method on the Application
class. It should shut down your application, and as a result, all of the
windows that go with it.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com
"PawelR" <pa************@poczta.onet.pl> wrote in message
news:MP************************@news.tpi.pl... Hello group, In my apps I connection to SQL database. try { //connect to db } catch { MessageBox("Error Connect. Close Apps?","Sql Error",MessageBoxButtons.OKCancel,MessageBoxIcon.E rror);
} When db is connection error apps show messagebox with button OK and
Cancel. My question: How close this application after OK, and continuue apps after Cancel?
catch { MessageBox("Error Connect","Sql Error",MessageBoxButtons.OK,MessageBoxIcon.Error); Close(); } Not work.
Thx PawelR
this.Close();
should close the current thread(program).
However, if you connect to the database as a part of a startup procedure
Close() will be ignored.
A possible solution to this is to throw a new exception after showing the
messagebox, and use a try/catch around Application.Run();
You put the messagebox in an if statement and compare it with
DialogResult.OK to check if OK was clicked.
[STAThread]
static void Main()
{
try
{
Application.Run(new Form1());
}
catch
{
}
}
(...)
try
{
//connect to db
}
catch
{
if(MessageBox("Error Connect. Close Apps?", "Sql Error",
MessageBoxButtons.OKCancel,MessageBoxIcon.Error) == DialogResult.OK)
{
throw new Exception();
}
}
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: William Gill |
last post by:
I am trying to make a simple data editor in Tkinter where each data
element has a corresponding Entry widget. I have tried to use the
FocusIn/FocusOut events to set a 'hasChanged' flag (if a...
|
by: John H. |
last post by:
Hello
I have some trouble in closing a window, Here is the problem:
I develop a asp.net website use client side valiation
<asp:CustomValidator id="CustomValidator1"...
|
by: Steven Malcolm |
last post by:
Hello there
Is it possible to close a window without the messagebox coming up asking if
you really want to close the window?
Steven
|
by: Alpha |
last post by:
I have a Window based application that shows up still running in the task
manager when I close it. It reaches the "this.close" statement and then it
stops at the "}" at the section of the...
|
by: John H. |
last post by:
Hello
I have some trouble in closing a window, Here is the problem:
I develop a asp.net website use client side valiation
<asp:CustomValidator id="CustomValidator1"...
|
by: mg |
last post by:
Once opening WebForm2 from WebForm1 using
Response.Write("<script language='javascript'>window.open
('WebForm2.aspx','two','menubar=no');</script>");
how can I close WebForm1?
|
by: Nicola Farina |
last post by:
Hi all,
I've a window form application with 3 forms. I want to catch the
security exception when users run this application from a network share,
thus I've made this code (I've notice that...
|
by: RSH |
last post by:
I am trying to figure out how I can trap the Closing Event that occurs when
a user attempts to close the window by clicking on the red"X".
I tried this code which I found online but nothing...
|
by: Frank Rizzo |
last post by:
I am trying to programmatically close a messagebox. I don't see any
obvious managed choices. Back in the day, I remember using a
combination of FindWindow and EndDialog apis(...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |