0
Great, I’m running a project for my PEF that consists of creating a BD for a company. However, I decided to put a button to add records and when I click to add, the following error appears: Failed to convert the value of the Datatimepicker parameter to Datetime What can I do? I leave you the following image that contains and the image of the error and send the code here:
SqlCommand command = new SqlCommand("insert into Utilizador(IDuser, Nome, Localidade, DataDeNascimento, Idade, Email, Login, Senha, Telefone, TelefoneEE, Perfil, Imagem)
values (@IDuser, @Nome, @Localidade, @DatadeNascimento, @Idade, @Email, @Login, @Senha, @Telefone, @TelefoneEE, @Perfil, @Imagem", sql);
command.Parameters.Add("@IDuser", SqlDbType.VarChar).Value = iDuserTextBox.Text;
command.Parameters.Add("@Nome", SqlDbType.VarChar).Value = nomeTextBox.Text;
command.Parameters.Add("@Localidade", SqlDbType.VarChar).Value = localidadeTextBox.Text;
command.Parameters.Add("@DataDeNascimento", SqlDbType.DateTime).Value = dataDeNascimentoDateTimePicker;
command.Parameters.Add("@Idade", SqlDbType.VarChar).Value = idadeTextBox.Text;
command.Parameters.Add("@Email", SqlDbType.VarChar).Value = emailTextBox.Text;
command.Parameters.Add("@Login", SqlDbType.VarChar).Value = loginTextBox.Text;
command.Parameters.Add("@Senha", SqlDbType.VarChar).Value = senhaTextBox.Text;
command.Parameters.Add("@Telefone", SqlDbType.Char).Value = telefoneTextBox.Text;
command.Parameters.Add("@TelefoneEE", SqlDbType.Char).Value = telefoneEETextBox.Text;
command.Parameters.Add("@Imagem", SqlDbType.Image).Value = imagemPictureBox.Image;
command.Parameters.Add("@Perfil", SqlDbType.VarChar).Value = perfilTextBox.Text;
Thanks for the help. Hug
Good, I did what you suggested and another error appeared to me... this time as: Failed to convert the value of the Bitmap parameter to Byte[]. I guess it’s the Image not?
– Leandro Gonçalves
Yes, you need to check the return type of "imagePictureBox.Image" and convert it to the appropriate columnar value of your BD.
– Neto Costa
Forgive my ignorance, but I’m still a beginner in programming... How do I accomplish what you explained?
– Leandro Gonçalves