Unhandled exception

Hi there.
In VB.NET project I used VB6 ADO Data Control and made some bindings:


ADOBind_Adodc1 = New VB6.MBindingCollection()
ADOBind_Adodc1.DataSource = CType(Adodc1, msdatasrc.DataSource)
ADOBind_Adodc1.Add(Text1, "Text", "Word", Nothing, "Text1")
ADOBind_Adodc1.UpdateMode = VB6.UpdateMode.vbUpdateWhenPropertyChanges
ADOBind_Adodc1.UpdateControls()

Everything works fine, except when I'm entering non valid value to textbox (like entered string's length exceeds field size) exception is generated and program is crashed.

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Runtime.InteropServices.COMException (0x80040E21): Multiple-step operation generated errors. Check each status value.
at Microsoft.VisualBasic.Compatibility.VB6.IRowsetChange.SetData(Int32 hRow, Int32 hAccessor, IntPtr pData)
at Microsoft.VisualBasic.Compatibility.VB6.Accessor.SetData(Int32 hrow, Object val)
at Microsoft.VisualBasic.Compatibility.VB6.MBinding.SetData()
at Microsoft.VisualBasic.Compatibility.VB6.MBinding.OnPropertyChange(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnTextChanged(EventArgs e)
at System.Windows.Forms.TextBoxBase.WmReflectCommand(Message& m)
at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
at System.Windows.Forms.TextBox.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

I can't catch this exception in no way.
Any ideas how and where I can handle this?
Thanks in advance.
[1904 byte] By [dav79] at [2007-11-19 11:28:34]
# 1 Re: Unhandled exception
Maybe you need to control the input to the TextBox so that it is always valid.
jmcilhinney at 2007-11-10 3:16:52 >
# 2 Re: Unhandled exception
yes, that is possible, but I have a lot of binded controls and write special validating code for each of them is a little bit hard :-(
dav79 at 2007-11-10 3:17:52 >
# 3 Re: Unhandled exception
If your bound table has constraints then you need to ensure that those constraints are enforced. You need to validate the input somewhere. You should always code to avoid exceptions if at all possible. Allowing the user to enter invalid values and then handling the exception is bad coding practice if it can be avoided. Even if you do that, though, you still need to tell the user what IS valid input, so you still need to know what the constraints are for each individual control.

You may have a very good reason to, but if possible you should avoid writing new code using ADO. All new code should be written using ADO.NET unless it is extending or modfying a project that has been upgraded from VB6. Even then, you should try to incorporate ADO.NET if possible.
jmcilhinney at 2007-11-10 3:18:53 >
# 4 Re: Unhandled exception
ok, thanks a lot
dav79 at 2007-11-10 3:19:58 >