In following code I purposefully mistype “@fooData” to “@foo111Data” to check if the try statement is catching my exception. See below code. But the try/catch statement did not catch and display and exception in MessageBox, and VS2010 just break down and highlight the line of wrong code.
try
{
conn.Open();
cmd.Parameters.AddWithValue("@foo111Data", dataStrTb1.Text);
cmd.ExecuteNonQuery();
}
catch (SqlCeException ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
conn.Close();
}
Perhaps an exception of a different type is being thrown? I would suggest that you change the
catchso that it just catches a generalException, and see if it’s throwing another type.Put a breakpoint in the
catchstatement, on theMessageBox.Showline, and then you can examine theException.