User-290759768 posted
This is my first assignment for C# and new to the syntax. Here is my insert function, where and how the syntax to write for if record already exist in database and prompt a message box?
protected void btnInsertion_Click(object sender, EventArgs e)
{
try /* Insertion After Validations*/
{
using (NpgsqlConnection connection = new NpgsqlConnection())
{
connection.ConnectionString = ConfigurationManager.ConnectionStrings["constr"].ToString();
connection.Open();
NpgsqlCommand cmd = new NpgsqlCommand();
cmd.Connection = connection;
cmd.CommandText = "INSERT INTO student_folio (f_name,l_name)VALUES(@f_name, @l_name) " ;
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(new NpgsqlParameter("@f_name", txtFname.Text));
cmd.Parameters.Add(new NpgsqlParameter("@l_name", txtLname.Text));
cmd.ExecuteNonQuery();
cmd.Dispose();
connection.Close();
Bind();
clearForm();
}
}
catch (Exception ex)
{
throw ex;
}
}//end of btnInsertion_Click