Blackvelvet Posted February 29, 2012 Report Share Posted February 29, 2012 Boas a todos, Mais uma vez venho pedir a vossa ajuda.... Estou a fazer uma aplicação para gestão de um parque informatico. O problema é que quanto testo o insert dá-me o erro :"Failed to convert parameter value from a Boolean to a Byte[]." Deixo o codigo aqui: Private Sub btnOk_Click(sender As System.Object, e As System.EventArgs) Handles btnOk.Click ' Try ' Texto de ligação à base de dados Dim myConnectionString As String = _ "Data Source=.\SQLEXPRESS; Initial Catalog=GestInformatica; Integrated Security=SSPI;" ' Comando que irá inserir dados na tabela "GestInformatica" os campos 'que são passados através de parâmetros Dim SQL As String = "INSERT INTO gestao ([empresa],[nome_rede],[utilizador],[local],[departamento],[visivel_rede],[sistema_operativo],[selo_windows],[office],[licenca],[numero_office],[autenticacao],[office_audit],[nome],[server_cal],[ex_cal],[sql_cal],[utiliza],[user_citrix],[user_internet],[observacao],[fotoffice],[fotowin]) VALUES (@empresa, @nome_rede,@utilizador,@local,@departamento,@visivel_rede,@sistema_operativo,@selo_windows,@office,@licenca,@numero_office,@autenticacao,@office_audit,@nome,@server_cal,@ex_cal,@sql_cal,@utiliza,@user_citrix,@user_internet,@observacao,@fotoffice,@fotowin);" ' Cria uma nova ligação à base de dados Dim connection As New SqlConnection(myConnectionString) ' Criação do comando indicando a instrução e a ligação Dim command As New SqlCommand(SQL, connection) ' Indicação dos parâmetros que serão inseridos command.Parameters.Add("@empresa", SqlDbType.VarChar).Value = cbxEmpresa.Text command.Parameters.Add("@nome_rede", SqlDbType.VarChar).Value = txtNomeRede.Text command.Parameters.Add("@utilizador", SqlDbType.VarChar).Value = txtUtilizador.Text command.Parameters.Add("@local", SqlDbType.VarChar).Value = cbxLocalizacao.Text command.Parameters.Add("@departamento", SqlDbType.VarChar).Value = cbxDepartamento.Text command.Parameters.Add("@visivel_rede", SqlDbType.Int).Value = cbxVisivel_Rede.Text command.Parameters.Add("@sistema_operativo", SqlDbType.VarChar).Value = txtSO.Text command.Parameters.Add("@selo_windows", SqlDbType.VarChar).Value = txtSeloWindows.Text command.Parameters.Add("@office", SqlDbType.VarChar).Value = txtOffice.Text command.Parameters.Add("@licenca", SqlDbType.VarChar).Value = txtSeloOffice.Text command.Parameters.Add("@numero_office", SqlDbType.Int).Value = txtNOffice.Text command.Parameters.Add("@autenticacao", SqlDbType.VarChar).Value = cbxLegal.Text command.Parameters.Add("@office_audit", SqlDbType.VarChar).Value = txtOfficeAuditoria.Text command.Parameters.Add("@nome", SqlDbType.VarChar).Value = cbxDL.Text command.Parameters.Add("@server_cal", SqlDbType.Int).Value = cbxServer.Text command.Parameters.Add("@ex_cal", SqlDbType.Int).Value = cbxEx.Text command.Parameters.Add("@sql_cal", SqlDbType.Int).Value = cbxSQL.Text command.Parameters.Add("@utiliza", SqlDbType.VarChar).Value = cbxUserBaan.Text command.Parameters.Add("@user_citrix", SqlDbType.VarChar).Value = cbxUserCitrix.Text command.Parameters.Add("@user_internet", SqlDbType.VarChar).Value = cbxUserInternet.Text command.Parameters.Add("@observacao", SqlDbType.VarChar).Value = txtObservacoes.Text command.Parameters.Add("@fotoffice", SqlDbType.Image).Value = pbxSeloOffice.Capture command.Parameters.Add("@fotowin", SqlDbType.Image).Value = pbxSeloWindows.Capture ' Abre a ligação, executa o comando e guarda em "x" o número de registos inseridos connection.Open() Dim x As Integer = command.ExecuteNonQuery() If x < 1 Then End If ' Fecha a ligação e limpa as variáveis connection.Close() connection = Nothing command = Nothing MsgBox(" Registo inserido com sucesso", MsgBoxStyle.Information) ' Catch ex As Exception MessageBox.Show("A operação efectuada não retomou qualquer resultado.") ' End Try End Sub E já agora,aproveito para perguntar se esta parte do codigo está correcta. ..., SqlDbType.Image).Value = pbxSeloOffice.Capture ..., , SqlDbType.Image).Value = pbxSeloWindows.Capture Um abraço EDIT: GeSHi adicionado Link to comment Share on other sites More sharing options...
Caça Posted February 29, 2012 Report Share Posted February 29, 2012 Não, essas propriedades são do tipo boolean e o que queres é um array de bytes. Ai tens de passar apenas a imagem. Pedro Martins Não respondo a duvidas por PM Link to comment Share on other sites More sharing options...
Blackvelvet Posted February 29, 2012 Author Report Share Posted February 29, 2012 Ok, podes dizer como faço isso? Sou muito verde em vb. ? Aquele abraço Link to comment Share on other sites More sharing options...
Caça Posted February 29, 2012 Report Share Posted February 29, 2012 https://wiki.portugal-a-programar.pt/dev_net:vb.net:inserir_imagens_sql_server Pedro Martins Não respondo a duvidas por PM Link to comment Share on other sites More sharing options...
Blackvelvet Posted February 29, 2012 Author Report Share Posted February 29, 2012 Obrigado pela ajuda. 🙂 Um abraço Link to comment Share on other sites More sharing options...
Tiago Simões Marques Posted March 16, 2012 Report Share Posted March 16, 2012 Um conselho na parte dos comandos que têm "@" (Por exemplo: "nome_rede") não utilizes "_" Alteras VALUES (@nome_rede) para VALUES (@nomerede) Tiago Simões Marques Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now