Hello,
I am using a try....catch statement in my code that doesn't seem to be working properly. I may be doing something a bit different to the standard, so I'll explain the best I can.
I have a 3 tier application, and in my class I have the following code :
All this does is uipdate the table if the reference doesn't already exist, and if it does, it brings back the message advising that the update failed.Code:Try AdaptSql = New Data.DetailsAdapter(SQL_ConnectionString) m_TDS = New DetailsTDS AdaptSql.Fill(m_TDS, m_EERef) If m_TDS.Tables(0).Rows.Count = 0 Then m_Row = m_TDS.tbl_Details.NewRow m_Row.ID = m_ID m_TDS.tbl_Details.Addtbl_DetailsRow(m_Row) m_Row.EndEdit() AdaptSql.Update(m_TDS) Else MsgBox("This Reference already exists!", MsgBoxStyle.Critical, "Reference Already Exists") End If m_Row = Nothing m_TDS.Dispose() AdaptSql = Nothing Catch ex As Exception MsgBox(ex.Message) End Try
This works fine.
However in my code on the form I also have :
Now I would expect that if the code in the class fails (because the reference already exists), then the messagebox here shouldn't show.Code:Try ID.Update_New(txtID.Text) MessageBox.Show("Your New ID has been logged.", "ID Added", MessageBoxButtons.OK, MessageBoxIcon.Information) Catch ex As Exception MsgBox(ex.Message) End Try
However it does - It seems as though regardless of what happens in the class (whether the ID is added or not) both lines in the form run.
What am I doing wrong please ?




Reply With Quote