0
Good, I am conducting a project for my PEF that consists in creating a Database 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 Bitmap parameter to Byte[]. What should I do? I leave you the following image that contains 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.Value;
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;

Good, I put this code before private void btnAionar_Click? Or inside it?
– Leandro Gonçalves
It can be inside even, depends on how you ta structuring your project
– Vitor Ceolin
Good, I did what you suggested but gave error in Imageconverter converter = new Imageconverter(); image = (byte[])convert.Convertto(img, typeof(byte[]); instead of meti image Imagempicturebox but at img I don’t know what to change
– Leandro Gonçalves
puts the image you want to convert in place of
img, inimagemis the name of the variable you will store, then you will send to the bank the variableimagem– Vitor Ceolin
So I left the code: Imageconverter converter = new Imageconverter(); image = (byte[])convert.Convertto(imagemPictureBox, typeof(byte[]); ...
– Leandro Gonçalves