Thank you for your message! Beceause now i try to learn some C# programming (and write in english), your message help me to understand about Try catch. Just to be sure that i have understand: 1. I have my btnSave code that look like this:
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
int x = 0; //this will be the ID of the new inserted record
x = SaveData();
if (x > 0)
{
lblMesaje.Text = " Your new ID is: " + x.ToString();
}
}
catch (Exception ex)
{
lblMesage.Text = "Some error occured: " + ex.Message;
}
}
2. Now here is my Insert function:
private int SaveData()
{
//SQL objects set..
int result= 0;
try
{
if (sqlconn.State != ConnectionState.Open)
{
sqlconn.Open();
}
result= Convert.ToInt32(cmd.ExecuteScalar());
return result;
}
catch (Exception)
{
throw;
}
finally
{
if (sqlconn.State != ConnectionState.Closed)
{
sqlconn.Close();
}
}
}
Now i throw and exception in SaveData function and the message is displayed to the user. Is ok? Thanks again!