Try and Catch
Actually use in C # Application connect with database
Try
{
string conString = ConfigurationManager.ConnectionStrings ["ldr"]. ConnectionString;
using (SqlConnection con = new SqlConnection (conString))
{
using (SqlCommand cmd = new SqlCommand ("StuProc", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue ("@First", firstname.Text);
cmd.Parameters.AddWithValue ("@Last", lastname.Text);
cmd.Parameters.AddWithValue ("@Phone", phonebox.Text);
cmd.Parameters.AddWithValue ("@Email", emailbox.Text);
cmd.Parameters.AddWithValue ("@ is # Intrest", csharExperties.Checked);
cmd.Parameters.AddWithValue ("@isJavaIntrest", javaExperties.Checked);
cmd.Parameters.AddWithValue ("@isVBIntrest", VBExperties.Checked); con.Open ();
cmd.ExecuteNonQuery (); Result DialogResult = MessageBox.Show ("Your data is stored", "Successfully", MessageBoxButtons.OK, MessageBoxIcon.Information);
switch (result)
{
case DialogResult.OK:
ClearScreen ();
break;
}
}
}
}
catch (Exception ex)
{MessageBox.Show ("Problem:", ex.Message);
}
}If there is any error in your connection, such as configuration, procedure, parameter and Initialization, then it will warn you of your error in this area
source share