hypz Posted June 13, 2012 at 10:23 AM Report Share #462428 Posted June 13, 2012 at 10:23 AM (edited) Boas, alguém me pode dizer como faço esta query sem dar erro na sintaxe ? Não sei se devo usar apenas "&" para junta-las ou usar mesmo outra função sem ser o "And" Dim sql As String = "Update Carregamento set Valor_Base=" & valor_base & "And Cod_Cliente=" & cod_cliente & "And Valor_IVA=" & valor_iva & "And Valor_Total=" & valor_total Edited June 13, 2012 at 10:26 PM by Caça GeSHi Link to comment Share on other sites More sharing options...
jpaulino Posted June 13, 2012 at 10:49 AM Report Share #462438 Posted June 13, 2012 at 10:49 AM Repara na concatenação que estás a fazer, no excerto: ... valor_base & "And Cod_Cliente=" & cod_cliente & "And ... se a variável valor_base for 500 e o cod_cliente 50, o resultador será: 500And Cod_Cliente=50And O que dará obviamente erro! Tens de dar uns espaços: Dim sql As String = "Update Carregamento set Valor_Base=" & valor_base & " And Cod_Cliente=" & cod_cliente & " And Valor_IVA=" & valor_iva & " And Valor_Total=" & valor_total Link to comment Share on other sites More sharing options...
petvetbr Posted June 13, 2012 at 10:55 AM Report Share #462439 Posted June 13, 2012 at 10:55 AM (edited) Procure verificar se sintaxe do comando Update que esta utilizando é compatível com o seu banco de dados. Isto pode ser feito rodando o comando separadamente direto no banco de dados. Edited June 13, 2012 at 11:01 AM by petvetbr Fernando Lage Bastos - MCP/MCTS/MCPD Link to comment Share on other sites More sharing options...
jpaulino Posted June 13, 2012 at 11:01 AM Report Share #462441 Posted June 13, 2012 at 11:01 AM Procure estudar como escrever o Update em SQL. Algumas coisas que notei: Nem reparei que era um UPDATE 😛 (só olhei para os espaços) Link to comment Share on other sites More sharing options...
hypz Posted June 13, 2012 at 02:03 PM Author Report Share #462495 Posted June 13, 2012 at 02:03 PM (edited) Pois, eu não sei se a query está correta mas ele está na mesma a fazer-me as contas certas, só não está é a executar direito a query. Continua a dar-me erro na query 🙂 Edited June 13, 2012 at 02:33 PM by hypz Link to comment Share on other sites More sharing options...
Caça Posted June 14, 2012 at 09:05 AM Report Share #462623 Posted June 14, 2012 at 09:05 AM Tenta assim Dim sql As String = "Update Carregamento set Valor_Base=" & valor_base & ", Cod_Cliente=" & cod_cliente & ", Valor_IVA=" & valor_iva & ", Valor_Total=" & valor_total & " WHERE IDCarregamento = Teu_Carregamento Pedro Martins Não respondo a duvidas por PM Link to comment Share on other sites More sharing options...
hypz Posted June 14, 2012 at 09:23 AM Author Report Share #462633 Posted June 14, 2012 at 09:23 AM O que é isso do IDCarregamento = TeuCarregamento ? Link to comment Share on other sites More sharing options...
Caça Posted June 14, 2012 at 09:26 AM Report Share #462634 Posted June 14, 2012 at 09:26 AM É só para actualizar o carregamento em que estás a trabalhar, caso contrario vai actualizar a tabela toda com os mesmos dados. Pedro Martins Não respondo a duvidas por PM Link to comment Share on other sites More sharing options...
hypz Posted June 14, 2012 at 09:44 AM Author Report Share #462640 Posted June 14, 2012 at 09:44 AM Dá-me erro é neste update "Dim sql As String = "Update Utilizador set Montante_Disponivel=" & valor_total & "WHERE Cod_Cartao =" & cod_cliente" mas eu uso este query noutra form e ele funciona perfeitamente. Eu aqui estou a inserir dados numa tabela chamada "Carregamento" e depois quero atualizar a tabela "Utilizador" mal ele calcule os valores e insira lá, é possivel ? Link to comment Share on other sites More sharing options...
Caça Posted June 14, 2012 at 09:46 AM Report Share #462643 Posted June 14, 2012 at 09:46 AM Para inserir dados a instrução utilizada é a INSERT. Pedro Martins Não respondo a duvidas por PM Link to comment Share on other sites More sharing options...
hypz Posted June 14, 2012 at 09:54 AM Author Report Share #462651 Posted June 14, 2012 at 09:54 AM (edited) Sim, isso eu sei, pera. TextBox2.Text = TextBox3.Text * 0.23 TextBox1.Text = TextBox3.Text - TextBox2.Text TextBox2.Visible = True TextBox1.Visible = True Label1.Visible = True Label2.Visible = True Dim dr As DialogResult dr = MsgBox("Deseja Adicionar ?", MessageBoxButtons.YesNo, "Adicionar Carregamento") If dr = DialogResult.Yes Then Dim provider As String provider = "provider = Microsoft.ACE.OLEDB.12.0;Data Source=Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\hypz\Ambiente de trabalho\pap_teste.accdb; persist security info = false;" Dim con As New OleDbConnection(provider) con.Open() Dim query As String = "INSERT INTO Carregamento([Cod_Recibo], [Cod_Cliente], [Nome_Cliente], [Data_Carregamento], [Valor_Base], [Valor_IVA], [Valor_Total]) VALUES (@Cod_Recibo, @Cod_Cliente, @Nome_Cliente, @Data_Carregamento, @Valor_Base, @Valor_IVA, @Valor_Total)" Dim sql As String = "Update Utilizador set Montante_Disponivel=" & valor_total & "WHERE Cod_Cartao =" & cod_cliente Dim sqlcom As New OleDbCommand(sql, con) Dim nr As Integer nr = sqlcom.ExecuteNonQuery() Dim command As New OleDbCommand(query, con) command.Parameters.Add("@Cod_Recibo", OleDbType.VarChar).Value = TextBox5.Text command.Parameters.Add("@Cod_Cliente", OleDbType.VarChar).Value = TextBox4.Text command.Parameters.Add("@Nome_Cliente", OleDbType.VarChar).Value = TextBox6.Text command.Parameters.Add("@Data_Carregamento", OleDbType.DBDate).Value = DateTimePicker1.MaxDate command.Parameters.Add("@Valor_Base", OleDbType.VarChar).Value = TextBox1.Text command.Parameters.Add("@Valor_IVA", OleDbType.VarChar).Value = TextBox2.Text command.Parameters.Add("@Valor_Total", OleDbType.VarChar).Value = TextBox3.Text Dim x As Integer = command.ExecuteNonQuery() If x < 1 Then MessageBox.Show("Erro ao inserir", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error) Else MessageBox.Show("Registo inserido com sucesso!", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Information) Dim sql1 As String = "Select * from Carregamento" Dim da As OleDbDataAdapter da = New OleDbDataAdapter(sql1, con) Dim ds As DataSet ds = New DataSet() da.Fill(ds) End If con.Close() command = Nothing ElseIf dr = DialogResult.No Then MsgBox("Carregamento Não Adicionado.") End If Dá-me erro no Update do Utilizador. Edited June 14, 2012 at 09:59 AM by Caça Link to comment Share on other sites More sharing options...
Caça Posted June 14, 2012 at 10:00 AM Report Share #462656 Posted June 14, 2012 at 10:00 AM Que update? Não vejo ai update nenhum.. Uma coisa de cada vez, agora estamos com o Carregamento, ok? Pedro Martins Não respondo a duvidas por PM Link to comment Share on other sites More sharing options...
hypz Posted June 14, 2012 at 10:31 AM Author Report Share #462666 Posted June 14, 2012 at 10:31 AM O Carregamento funciona com o inserir, ele insere. mas nisto Dim sql As String = "Update Utilizador set Montante_Disponivel=" & valor_total & "WHERE Cod_Cartao =" & cod_cliente Dim sqlcom As New OleDbCommand(sql, con) Dim nr As Integer nr = sqlcom.ExecuteNonQuery() Ele dá-me erro na sintaxe da query. Link to comment Share on other sites More sharing options...
Caça Posted June 14, 2012 at 10:34 AM Report Share #462667 Posted June 14, 2012 at 10:34 AM Uma coisa de cada vez, estávamos a ver isto Dim sql As String = "Update Carregamento set Valor_Base=" & valor_base & ", Cod_Cliente=" & cod_cliente & ", Valor_IVA=" & valor_iva & ", Valor_Total=" & valor_total & " WHERE IDCarregamento = Teu_Carregamento Já está resolvido? Pedro Martins Não respondo a duvidas por PM Link to comment Share on other sites More sharing options...
hypz Posted June 14, 2012 at 10:36 AM Author Report Share #462669 Posted June 14, 2012 at 10:36 AM Sim, isso está. Agora o outro update é que não 🙂 Link to comment Share on other sites More sharing options...
Caça Posted June 14, 2012 at 10:37 AM Report Share #462670 Posted June 14, 2012 at 10:37 AM Tens que dar espaços Dim sql As String = "Update Utilizador set Montante_Disponivel = " & valor_total & " WHERE Cod_Cartao = " & cod_cliente Pedro Martins Não respondo a duvidas por PM Link to comment Share on other sites More sharing options...
hypz Posted June 14, 2012 at 10:40 AM Author Report Share #462671 Posted June 14, 2012 at 10:40 AM (edited) Senão tiver espaços é aquele problema do tipo "CodCartao=1codcliente=2" e ele não consegue ler certo? Continua a dar-me erro na sintaxe da query update.. Edited June 14, 2012 at 10:42 AM by hypz Link to comment Share on other sites More sharing options...
Caça Posted June 14, 2012 at 10:57 AM Report Share #462676 Posted June 14, 2012 at 10:57 AM Certo, tenta assim Dim sql As String = "Update [utilizador] set [Montante_Disponivel] = " & valor_total & " WHERE [Cod_Cartao] = " & cod_cliente Se continuar a dar erro pega na query final e executa-a directamente no Access Pedro Martins Não respondo a duvidas por PM Link to comment Share on other sites More sharing options...
hypz Posted June 14, 2012 at 10:59 AM Author Report Share #462677 Posted June 14, 2012 at 10:59 AM Será que tem haver com a posição da query ? Ser logo depois do Insert ? Link to comment Share on other sites More sharing options...
Caça Posted June 14, 2012 at 11:09 AM Report Share #462688 Posted June 14, 2012 at 11:09 AM Não, não tem nada a haver, executa-a no Access. O que é que vai nas variáveis valor_total e cod_cliente? Pedro Martins Não respondo a duvidas por PM 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