In the following code, I purposefully apply "@fooData" to "@ foo111Data" to see if the try statement captures my exception. See below code. But the try / catch statement did not catch and did not display an exception in the MessageBox, and VS2010 just broke and highlighted a line of incorrect code.
try
{
conn.Open();
cmd.Parameters.AddWithValue("@foo111Data", dataStrTb1.Text);
cmd.ExecuteNonQuery();
}
catch (SqlCeException ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
conn.Close();
}
source
share