Query of dataset that shows last ID created giving error

0

I am making a people registration form which when I finish entering the data it shows a MessageBox saying with which ID the person was registered. For this I use a% w of% of my query (I'm using Entity Framework model first), but for some reason this is giving error that "One or more lines contain values that violate the non-null, unique or foreign-key constraints . ", due to this I think it's an error in the bank code, maybe not.

Follow the query code:

SELECT MAX(ID_Pacientes) as UltimoID FROM Pacientes_TCC

The field dataset is of autro increment and is primary key.

Code where I implement the query:

 private void btnInserir_Click(object sender, EventArgs e)
        {

            Pacientes_TCCTableAdapter TaPaciente = new Pacientes_TCCTableAdapter();

            TaPaciente.Insert(txtNome.Text, txtCPF.Text, txtRG.Text, cbxSexo.Text, dtpData.Value, txtCidade.Text, txtEstado.Text, txtBairro.Text, txtCEP.Text,
                txtRua.Text, txtNumero.Text, txtCelular.Text, txtFixo.Text, txtEmail.Text, cbxConvenio.Text);

            if (MessageBox.Show("Pessoa gravado com o ID" +TaPaciente.UltimoID()+ " Deseja fazer outro cadastro?", "Confirma", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                Close();
            }



        }
    
asked by anonymous 10.11.2016 / 15:47

0 answers