MS Access Exceptions in VB.net

Victor

Member
Joined
Dec 14, 2004
Messages
7
Programming Experience
10+
Hello All,

I am wondering if there is any way that you know what type of exception has been thrown from MS Access?

for e.g. if there is an error inserting a record would it just throw a generic exception (InvalidOperationException or OleDBException) and you just catch it in VB or is there another way that you know specificaly what type of error occured.

Thanks for all of your help in advance.
 
Okay, as I understand this here is an example of where you can 'Trap' your error during a fictional 'Update' procedure. During the update procedure if something weird happens then it will resolve here within this function call.

From that point I can choose to deal with the error. Here I simply show a message box.

''' <summary>

''' Updates a record in the <c>Issues</c> table.

''' </summary>

''' <param name="value">The <see cref="IssuesRow"/>

''' <summary>

''' Updates a record in the <c>Issues</c> table.

''' </summary>

''' <param name="value">The <see cref="IssuesRow"/>

''' object used to update the table record.</param>

''' <returns>true if the record was updated; otherwise, false.</returns>

Public Overridable Function Update(value As IssuesRow) As Boolean

try

Dim sqlStr As String = "UPDATE [Issues] SET " + _

"[ProjectID]=" + _db.CreateSqlParameterName("ProjectID") + ", " + _

"[Title]=" + _db.CreateSqlParameterName("Title") + ", " + _

"[Status]=" + _db.CreateSqlParameterName("Status") + ", " + _

"[Severity]=" + _db.CreateSqlParameterName("Severity") + ", " + _

"[DateFound]=" + _db.CreateSqlParameterName("DateFound") + _

" WHERE " + _

"[IssueID]=" + _db.CreateSqlParameterName("IssueID")

Dim cmd As IDbCommand = _db.CreateCommand(sqlStr)

If value.IsProjectIDNull Then

AddParameter(cmd, "ProjectID", DBNull.Value)

Else

AddParameter(cmd, "ProjectID", value.ProjectID)

End If

AddParameter(cmd, "Title", value.Title)

AddParameter(cmd,
"Status", value.Status)

AddParameter(cmd,
"Severity", value.Severity)

AddParameter(cmd,
"DateFound", value.DateFound)

AddParameter(cmd,
"IssueID", value.IssueID)

Return 0 <> cmd.ExecuteNonQuery()

Catch ex as Exception

' Show the error that occured

msgbox( "The following error has ocurred: " & ex.message )

End try

End Function


 
Back
Top