|
-
April 30th, 2008, 11:54 AM
#1
Try Catch
Does anyone know how to catch an exception which happens when you try to add line in database(SQL Server 2005) through binding navigator and DataGridView at the same time in VC++.
-
April 30th, 2008, 03:59 PM
#2
Re: Try Catch
i assume you are using .net?
if you are using System.Data.SqlClient
have you tried catch (SqlException* e)
http://msdn.microsoft.com/en-us/libr...on(VS.71).aspx
-
April 30th, 2008, 06:19 PM
#3
Re: Try Catch
I know how to write an exception, but I don't know on which event should I write it(eg. mouse over datagridview).
-
April 30th, 2008, 06:49 PM
#4
Re: Try Catch
 Originally Posted by usingnamespace
I know how to write an exception, but I don't know on which event should I write it(eg. mouse over datagridview).
You write the code there where you wish to catch it, sounds stupid but you need todo something before you can catch it.
What im thinking is that you are trying to catch an exception that appears in the background or is generated by the object itself rather the programaticly or something or on a function call
adding it to mouseover is pointless unless in that function you have code that causes the exception
sorry i dont really understand?
-
April 30th, 2008, 07:05 PM
#5
Re: Try Catch
When I press the add button on the binding navigator and then I press on the empty row in DataGridView to add another row before I even inputed data in the first. That's when the exception happens because my database doesn't allow NULLS. Now I need to somehow catch that exception.
-
April 30th, 2008, 07:33 PM
#6
Re: Try Catch
 Originally Posted by usingnamespace
When I press the add button on the binding navigator and then I press on the empty row in DataGridView to add another row before I even inputed data in the first. That's when the exception happens because my database doesn't allow NULLS. Now I need to somehow catch that exception.
ah ok now i understand, im not 100% sure on that because i practicly never used the databindings in .net
however a quick look at thww datagridview events (under focus) shows
CellEnter
CellLeave
CellValidating
Void dataGridView1_CellValidating(System::Object^ sender, System::Windows::Forms: ataGridViewCellValidatingEventArgs^ e)
{
// the pointer 'e' has a couple if items that could e of use to you
// example
if cell == empty then e->Cancel = true;
}
As i said never used them before so not sure if its any help, so i decided t take a quick look at them and i think thats the direction you should look
-
May 13th, 2008, 04:43 PM
#7
Re: Try Catch
I still haven't figured out how to catch that error. Thanks anyway.
-
May 14th, 2008, 05:49 PM
#8
Re: Try Catch
I would rather say
Code:
try
{
// some dangerous code
}
catch( ... ) // this should catch ANY exception
{
cout<<" tra la la la la la la la"
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|