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++.
Printable View
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++.
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
I know how to write an exception, but I don't know on which event should I write it(eg. mouse over datagridview).
Quote:
Originally Posted by usingnamespace
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?
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 .netQuote:
Originally Posted by usingnamespace
however a quick look at thww datagridview events (under focus) shows
CellEnter
CellLeave
CellValidating
Void dataGridView1_CellValidating(System::Object^ sender, System::Windows::Forms::DataGridViewCellValidatingEventArgs^ 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
I still haven't figured out how to catch that error. Thanks anyway.
I would rather say
Code:try
{
// some dangerous code
}
catch( ... ) // this should catch ANY exception
{
cout<<" tra la la la la la la la"
}