set#1 Posted September 16, 2009 at 09:58 AM Report Share #287264 Posted September 16, 2009 at 09:58 AM Alo tudo bem! Tenho um probleminha. Tenho o codigo abaixo num botao "Apagar" que deve apagar um Paciente com o NID X numa BD (Server 2005) so que tenho o seguinte erro: Expression expected (sublinhado no primeiro &). Linha: pacientesDS = pacientesDTA.DeletePaciente(& Trim(txtNID.Text.ToString) &) DeletePaciente DELETE FROM t_paciente WHERE (nid = @Param1) O codigo completo: 'Com problemas ainda Private Sub btApagar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btApagar.Click 'Me tinham sugerido este mas isto so apaga no form e nao na BD 'Me.T_pacienteBindingSource.RemoveCurrent() 'Me.Update() Dim pacientesDS As BD_TL2009DataSet.t_pacienteDataTable Dim pacientesDTA As New BD_TL2009DataSetTableAdapters.t_pacienteTableAdapter pacientesDTA = New BD_TL2009DataSetTableAdapters.t_pacienteTableAdapter 'Dim paciente As BD_TL2009DataSet.t_pacienteRow If MsgBox("Tem a certeza que deseja apagar o registo: " & Trim(txtNID.Text) & " ?", MessageBoxButtons.YesNo, "Confime: Apagar Registo") = Windows.Forms.DialogResult.Yes Then pacientesDS = pacientesDTA.DeletePaciente(& Trim(txtNID.Text.ToString)&) MsgBox("Registo apagado com sucesso!", "Apagou Dados", MessageBoxButtons.OK) Else MsgBox("Registo nao apagado!", "Cancelou", MessageBoxButtons.OK) End If End Sub Obrigado pela atencao (((Peace&Love))) Link to comment Share on other sites More sharing options...
jpaulino Posted September 16, 2009 at 10:21 AM Report Share #287267 Posted September 16, 2009 at 10:21 AM Experimenta assim: pacientesDS = pacientesDTA.DeletePaciente(txtNID.Text.ToString.Trim()) O método pacientesDTA.DeletePaciente() devolve alguma coisa ? Caso contrário basta fazer: pacientesDTA.DeletePaciente(txtNID.Text.ToString.Trim()) Link to comment Share on other sites More sharing options...
set#1 Posted September 16, 2009 at 12:57 PM Author Report Share #287274 Posted September 16, 2009 at 12:57 PM Jpaulino, experimentei este: pacientesDTA.DeletePaciente(txtNID.Text.ToString.Trim()) Clico no botao apagar: 1o - Se esta a visualizar o paciente 001, pergunta na msgbox se quero apagar o paciente 002 (em vez de 001) e tanto Yes como No apaga o paciente anterior, o 001 e assim sucessivamente! 2o - Nao esta a apagar os dados na BD ? Usando pacientesDS = pacientesDTA.DeletePaciente(txtNID.Text.ToString.Trim()) Da este erro: Value of type 'Integer' cannot be converted to 'TL2009_SGP.BD_TL2009DataSet.t_pacienteDataTable'. O DeletePaciente me retorna um inteiro quando experimento e coloco o NID de qualquer paciente. Link to comment Share on other sites More sharing options...
jpaulino Posted September 16, 2009 at 01:01 PM Report Share #287275 Posted September 16, 2009 at 01:01 PM Mostra o código que tens em pacientesDTA.DeletePaciente Link to comment Share on other sites More sharing options...
set#1 Posted September 16, 2009 at 01:14 PM Author Report Share #287276 Posted September 16, 2009 at 01:14 PM Tenho um BD_TL2009DataSet onde ta la o t_paciente DataTable Nele tenho o t_pacienteTableAdapter onde tenho varias funções e uma delas 'e o DeletePaciente DELETE FROM t_paciente WHERE (nid = @Param1) O pacientesDTA foi declarado: Dim pacientesDTA As New BD_TL2009DataSetTableAdapters.t_pacienteTableAdapter pacientesDTA = New BD_TL2009DataSetTableAdapters.t_pacienteTableAdapter Espero ter feito perceber!! Link to comment Share on other sites More sharing options...
jpaulino Posted September 16, 2009 at 01:18 PM Report Share #287277 Posted September 16, 2009 at 01:18 PM Mas o que faz a função DeletePaciente ? Mostra o código. Link to comment Share on other sites More sharing options...
set#1 Posted September 16, 2009 at 01:24 PM Author Report Share #287279 Posted September 16, 2009 at 01:24 PM DELETE FROM t_paciente WHERE (nid = @Param1) Deve apagar na tabela t_paciente o paciente com o NID - txtNID No querybuilder ja executei e coloco um NID e ele apaga. Da pra perceber...?? Link to comment Share on other sites More sharing options...
set#1 Posted September 16, 2009 at 02:47 PM Author Report Share #287295 Posted September 16, 2009 at 02:47 PM Sorry jpaulino, eu 'e que falhei aqui: 'Me.T_pacienteBindingSource.RemoveCurrent() 'Me.Update() Comentei no post mas no programa nao estava comentado. Ja esta a funcionar B) Obrigado (((Peace&Love))) Link to comment Share on other sites More sharing options...
jpaulino Posted September 17, 2009 at 09:30 AM Report Share #287415 Posted September 17, 2009 at 09:30 AM Agora, ele apaga mas ainda me mostra o paciente, so depois de sair e voltar ao form 'e que actualiza. Como faco para ele depois actualizar para os dados actuas logo apos apagar. E como faco para ele mostrar num label o numero total dos pacientes na t_paciente. Mas mostra onde ? Esta questão já está resolvida, deves marcar como resolvida (Topic Solved) e criar uma nova questão 😛 Link to comment Share on other sites More sharing options...
set#1 Posted September 17, 2009 at 12:34 PM Author Report Share #287441 Posted September 17, 2009 at 12:34 PM Ja esta marcado. Esse outro ponto comecei em outro topico: Reload dados no form depois de apagar Obrigado (((Peace&Love))) 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