EdiSimoes Posted January 17, 2012 at 11:57 AM Report #432961 Posted January 17, 2012 at 11:57 AM Ola a todos, tenho uma duvida na minha aplicação, pois tenho um form com algumas checkbox, onde consegui fazer o insert, mais o update e o select, esta me deixando sem dormir, se alguem puder me ajudar: Para incluior uso esse: Private Sub incluir() Dim Con As New OleDbConnection Con.ConnectionString = My.Settings.CNS1 Try Con.Open() Catch ex As Exception MessageBox.Show("Erro ao tentar acessar conexão com o Banco de Dados." & ex.Message) Return End Try Dim Comando As New OleDbCommand Comando.CommandText = "INSERT INTO CadMotorista ( Nome, Cidade, TelFixo, TelCel, Observacao, EscAnterior, DataApresentacao, Contrato, Escalado, 1Safra, NaoPegar )" & _ " VALUES ( @Nome, @Cidade, @TelFixo, @TelCel, @Observacao, @EscAnterior, @DataApresentacao, @Contrato, @Escalado, @1Safra, @NaoPegar )" Comando.Parameters.Clear() Comando.Parameters.Add("@Nome", OleDbType.VarChar, 40).Value = txtNome.Text Comando.Parameters.Add("@Cidade", OleDbType.VarChar, 40).Value = txtCidade.Text Comando.Parameters.Add("@TelFixo", OleDbType.VarChar, 15).Value = mskTelFixo.Text Comando.Parameters.Add("@TelCel", OleDbType.VarChar, 15).Value = mskTelCel.Text Comando.Parameters.Add("@Observacao", OleDbType.VarChar, 255).Value = txtObsrv.Text Comando.Parameters.Add("@EscAnterior", OleDbType.VarChar, 10).Value = txtEscAnt.Text Comando.Parameters.Add("@DataApresentacao", OleDbType.VarChar, 12).Value = dtApresentacao.Text Comando.Parameters.Add("@Contrato", OleDbType.VarChar, 10).Value = cmbTipoContr.Text Comando.Parameters.Add("@Escalado", OleDbType.Boolean, 1).Value = CheckBox1.Checked Comando.Parameters.Add("@1Safra", OleDbType.Boolean, 1).Value = CheckBox2.Checked Comando.Parameters.Add("@NaoPegar", OleDbType.Boolean, 1).Value = CheckBox3.Checked Comando.CommandType = CommandType.Text Comando.Connection = Con Dim c As Integer Try c = Comando.ExecuteNonQuery Catch ex As Exception MessageBox.Show("Confira se todos os campos estão preenchidos." & ex.Message) Return End Try MessageBox.Show(String.Format("Registro inserido com Sucesso. - {0} registros ", c)) End Sub Para atualizar to tentando esse mais da erro de dados incompativeis: Dim Con As New OleDbConnection Con.ConnectionString = My.Settings.CNS1 Try Con.Open() Catch ex As Exception MessageBox.Show("Erro ao tentar acessar conexão com o Banco de Dados." & ex.Message) Return End Try Dim Comando As New OleDbCommand Comando.CommandText = "UPDATE CadMotorista SET Nome = '" & txtNome.Text & "' ," & _ "Cidade = '" & txtCidade.Text & "' ," & _ "TelFixo = '" & mskTelFixo.Text & "' ," & _ "TelCel = '" & mskTelCel.Text & "' ," & _ "Observacao = '" & txtObsrv.Text & "' ," & _ "EscAnterior = '" & txtEscAnt.Text & "' ," & _ " DataApresentacao = '" & dtApresentacao.Text & "' ," & _ "Contrato = '" & cmbTipoContr.Text & "' ," & _ "Escalado = '" & CheckBox1.Checked & "' ," & _ "1Safra = '" & CheckBox2.Checked & "' ," & _ "NaoPegar = '" & CheckBox3.Checked & "' " & _ " WHERE Codigo = " & txtCod.Text Comando.CommandType = CommandType.Text Comando.Connection = Con Dim c As Integer Try c = Comando.ExecuteNonQuery Catch ex As Exception MessageBox.Show("Erro ao gravar dados no Banco de Dados : " & ex.Message) Return End Try MessageBox.Show(String.Format("Dados Gravados com Sucesso! - {0} registros atualizados.", c)) Con.Close() Pesquisa.carregagrid() Edi Carlos Simões Estudante de Análise e Desenvolvimento de Sistemas edisimoes@bol.com.br http://www.desenvolvenetma.com.br http://analisedesistemas.bl.ee
Etiqueta Posted January 17, 2012 at 12:14 PM Report #432971 Posted January 17, 2012 at 12:14 PM tenta algo género este meu código está em c#, tenta adaptar para VB public void AlterarContacto() { SqlConnection connString = new SqlConnection(@"Data Source=INFORLANCASRV;Initial Catalog=GestAssist;User ID=sa;Password=SQLjoao"); string query = "UPDATE DB1_Contacto SET [iD_Contacto]=@ID_Contacto, [iD_TpContacto]=@ID_TpContacto, [Contacto]=@Contacto, [iD_Morada]=@ID_Morada, [iD_Individuo]=@ID_Individuo, [iD_Entidade]=@ID_Entidade"; SqlCommand command = new SqlCommand(query, connString); command.Parameters.Add("@ID_Contacto", SqlDbType.Int).Value = iD_ContactoTextBox; command.Parameters.Add("@ID_TpContacto", SqlDbType.Int).Value = tpContactoComboBox.SelectedValue; command.Parameters.Add("@Contacto", SqlDbType.Char).Value = contactoTextBox.Text; command.Parameters.Add("@ID_Morada", SqlDbType.Int).Value = iD_MoradaTextBox.Text; command.Parameters.Add("@ID_Individuo", SqlDbType.Int).Value = iD_IndividuoTextBox.Text; command.Parameters.Add("@ID_Entidade", SqlDbType.Int).Value = iD_EntidadeTextBox.Text; connString.Open(); int x = command.ExecuteNonQuery(); if (x < 1) MessageBox.Show("Erro ao alterar!", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Error); else MessageBox.Show("Dados da entidade alterados com sucesso!", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); connString.Close(); command = null; Facebook: https://www.facebook.com/DeArteaZ Blog: http://arte-a-z.blogspot.com
EdiSimoes Posted January 17, 2012 at 12:58 PM Author Report #432986 Posted January 17, 2012 at 12:58 PM Valeu meu amigo, deu certinho. Muito obrigado msm. Até a próxima. Edi Carlos Simões Estudante de Análise e Desenvolvimento de Sistemas edisimoes@bol.com.br http://www.desenvolvenetma.com.br http://analisedesistemas.bl.ee
Etiqueta Posted January 17, 2012 at 02:13 PM Report #433006 Posted January 17, 2012 at 02:13 PM De nada 😉 Até à próxima Facebook: https://www.facebook.com/DeArteaZ Blog: http://arte-a-z.blogspot.com
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