-1
Good morning guys, I’m trying to save some data in the database, for a button
of windows form C# and this error appears. I have tried everything but the error persists. I did the print and pasted the code of Forms and sql, please someone could help me?
strSql ="insert into Paciente
values(@IDPACIENTE,@NOMEPACIENTE,@SOBRENOME,@DATANASCIMENTO,
@GENERO,@CPF,@UFRG,@EMAIL,@CELULAR,@TELEFONEFIXO,
@PRONTUARIO,@CONVENIO,@CARTEIRINHACONVENIO,@VALIDADECARTEIRINHA)";
sqlCon = new SqlConnection(strCon);
SqlCommand comando = new SqlCommand(strSql, sqlCon);
comando.Parameters.Add("@IDPACIENTE", SqlDbType.Int).Value = textBox_ID.Text;
comando.Parameters.Add("@NOMEPACIENTE", SqlDbType.VarChar).Value = textBox_Nome.Text;
comando.Parameters.Add("@SOBRENOME", SqlDbType.VarChar).Value = textBox_SOBRENOME.Text;
comando.Parameters.Add("@DATANASCIMENTO", SqlDbType.DateTime).Value = maskedTextBox_DataNascimento.Text;
comando.Parameters.Add("@GENERO", SqlDbType.Char).Value =comboBox_Genero.Text;
comando.Parameters.Add("@CPF", SqlDbType.Char).Value =maskedTextBox_CPF.Text;
comando.Parameters.Add("@UFRG", SqlDbType.VarChar).Value = textBox_UFRG.Text;
comando.Parameters.Add("@EMAIL", SqlDbType.VarChar).Value =textBox_EMAIL.Text;
comando.Parameters.Add("@CELULAR", SqlDbType.VarChar).Value =maskedTextBox_CELULAR.Text;
comando.Parameters.Add("@TELEFONEFIXO", SqlDbType.VarChar).Value =maskedTextBox_TELEFONE.Text;
comando.Parameters.Add("@PRONTUARIO", SqlDbType.VarChar).Value =textBox_Prontuario.Text;
comando.Parameters.Add("@CONVENIO", SqlDbType.VarChar).Value =textBox_CONVENIO.Text;
comando.Parameters.Add("@CARTEIRINHACONVENIO", SqlDbType.VarChar).Value =textBox_CarteirinhaConvenio.Text;
comando.Parameters.Add("@VALIDADECARTEIRINHA", SqlDbType.DateTime).Value =maskedTextBox_ValidadeCarteirinha.Text;
try
{
sqlCon.Open();
comando.ExecuteNonQuery();
MessageBox.Show("Cadastro Efetuado Com Sucesso");
}
catch (Exception ex)
{
}
finally
{
sqlCon.Close();
CREATE TABLE Paciente(
IDPACIENTE INT IDENTITY PRIMARY KEY NOT NULL,
NOMEPACIENTE VARCHAR (50),
SOBRENOME VARCHAR (50),
DATANASCIMENTO DATETIME,
GENERO CHAR(1),
CPF CHAR(12) NOT NULL,
UFRG VARCHAR (50),
EMAIL VARCHAR (100),
CELULAR VARCHAR (100),
TELEFONEFIXO VARCHAR(10),
PRONTUARIO VARCHAR(100),
CONVENIO VARCHAR(100),
CARTEIRINHACONVENIO VARCHAR(100),
VALIDADECARTERINHA DATETIME
)
The error says that you cannot implicitly convert a string to date: in the form, it is string, in the database, it is date. You need to convert to date before saving, or change to bank (undeclared).
– rLinhares