AnaGPSI Posted June 6, 2012 at 01:24 PM Report Share #460858 Posted June 6, 2012 at 01:24 PM Tenho o seguinte código que não entra dentro do while, alguém me consegue explicar porque? Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click Const constr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\GPSI\Documents\mydb.accdb" Dim mydb As New OleDbConnection(constr) mydb.Open() 'MsgBox("State: " & mydb.State.ToString(), 'MsgBoxStyle.Information) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'saber id_momento e atribuir variavel Dim cod_momento As Integer Dim oledbCnn As OleDbConnection Dim oledbCmd As OleDbCommand Dim sql As String = "Select id_momento from momento where descri_momento='" & TextBox3.Text & "'" oledbCnn = New OleDbConnection(constr) Try oledbCnn.Open() oledbCmd = New OleDbCommand(sql, oledbCnn) Dim oledbReader As OleDbDataReader = oledbCmd.ExecuteReader() While oledbReader.Read cod_momento = oledbReader.Item(0) MsgBox(cod_momento) End While Finally End Try '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Atribuir variavel a numero de processo Dim numeroprocesso As Integer = TextBox2.Text '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'saber id_qualitativa e atribuir variavel Dim abc As Date = Format(datatime.Value.Date, "dd-MM-yyyy") MsgBox(abc) 'Format(datatime.Value, "dd-MM-yyyy") Dim cod_qualitativa As Integer Dim oledbCnn1 As OleDbConnection Dim oledbCmd1 As OleDbCommand MsgBox(datatime.Value.Date) Dim sql1 As String = "Select id_qualitativa from avaliacao_qualitativa where validade = " & abc & "" 'validade = " & datatime.Text & """ 'and n_processo=" & numeroprocesso & "" 'MsgBox(da.Text) MsgBox("ola") oledbCnn1 = New OleDbConnection(constr) Try oledbCnn1.Open() oledbCmd1 = New OleDbCommand(sql1, oledbCnn1) Dim oledbReader1 As OleDbDataReader = oledbCmd1.ExecuteReader() MsgBox("ola1") While oledbReader1.Read MsgBox("ola2") cod_qualitativa = oledbReader1.Item(0) MsgBox(cod_qualitativa) End While Finally End Try '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim sql3 As String = "Insert into apreciacao_global ([descr_apreci], [id_qualitativa]) values ('" & txtapreglobquali.Text & "', '" & cod_qualitativa & "') where ((avaliacao_qualitativa.id_qualitativa LIKE '%" & cod_qualitativa & "%'))" Dim cmd3 As New OleDbCommand(sql3, mydb) cmd3.ExecuteNonQuery() MsgBox("Apreciação global introduzida!") Não entra dentro deste while: While oledbReader1.Read MsgBox("ola2") cod_qualitativa = oledbReader1.Item(0) MsgBox(cod_qualitativa) End While alguém me consegue ajudar? Help me please Link to comment Share on other sites More sharing options...
Caça Posted June 6, 2012 at 01:28 PM Report Share #460861 Posted June 6, 2012 at 01:28 PM Antes de mais altera o titulo do tópico sff. Talvez porque oledbReader1.Read é igual a False Pedro Martins Não respondo a duvidas por PM Link to comment Share on other sites More sharing options...
ribeiro55 Posted June 6, 2012 at 01:30 PM Report Share #460864 Posted June 6, 2012 at 01:30 PM Vamos evitar títulos como "Help" de futuro, pode ser? Uma boa descrição breve é meio caminho andado para que não seja ignorado em primeiras instâncias. Quanto ao teu While, se não entra, é porque oledbReader1 não tem quaiseres resultados. Experimentaste a query directamente no Access? Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips" Link to comment Share on other sites More sharing options...
AnaGPSI Posted June 6, 2012 at 02:49 PM Author Report Share #460908 Posted June 6, 2012 at 02:49 PM (edited) Peço desculpa. Já agora como altero o nome do tópico? Sobre esse problema já consegui resolver-me só que agora dá-me o seguinte erro: A entrada da consulta tem que conter pelo menos uma tabela ou consulta na linha: cmd3.ExecuteNonQuery() do seguinte excerto: Dim sql3 As String = "Insert into apreciacao_global ([descr_apreci], [id_qualitativa]) values ('" & txtapreglobquali.Text & "', '" & cod_qualitativa & "') where ((avaliacao_qualitativa.id_qualitativa LIKE '%" & cod_qualitativa & "%'))" Dim cmd3 As New OleDbCommand(sql3, mydb) cmd3.ExecuteNonQuery() MsgBox("Apreciação global introduzida!") Com as alterações o código ficou assim: Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click Const constr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\GPSI\Documents\mydb.accdb" Dim mydb As New OleDbConnection(constr) mydb.Open() 'MsgBox("State: " & mydb.State.ToString(), 'MsgBoxStyle.Information) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'saber id_momento e atribuir variavel Dim cod_momento As Integer Dim oledbCnn As OleDbConnection Dim oledbCmd As OleDbCommand Dim sql As String = "Select id_momento from momento where descri_momento='" & TextBox3.Text & "'" oledbCnn = New OleDbConnection(constr) Try oledbCnn.Open() oledbCmd = New OleDbCommand(sql, oledbCnn) Dim oledbReader As OleDbDataReader = oledbCmd.ExecuteReader() While oledbReader.Read cod_momento = oledbReader.Item(0) MsgBox(cod_momento) End While Finally End Try '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Atribuir variavel a numero de processo Dim numeroprocesso As Integer = TextBox2.Text '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'saber id_qualitativa e atribuir variavel ' Dim abc As Date = Format(datatime.Value.Date, "dd-MM-yyyy") Dim abc As String abc = Format(DateTimePicker1.Value, "dd-MM-yyyy") & "%" 'Format(datatime.Value, "dd-MM-yyyy") Dim cod_qualitativa As Integer Dim oledbCnn1 As OleDbConnection Dim oledbCmd1 As OleDbCommand 'If abc = "2/2/2012" Then ' MsgBox("São iguais") 'Else ' MsgBox("Não são iguais") 'End If MsgBox(DateTimePicker1.Value.Date) Dim sql1 As String = "Select id_qualitativa from avaliacao_qualitativa where validade like '" & abc & "' and n_processo=" & numeroprocesso & "" 'validade = " & datatime.Text & """ 'and n_processo=" & numeroprocesso & "" 'MsgBox(da.Text) oledbCnn1 = New OleDbConnection(constr) Try oledbCnn1.Open() oledbCmd1 = New OleDbCommand(sql1, oledbCnn1) Dim oledbReader1 As OleDbDataReader = oledbCmd1.ExecuteReader() MsgBox("ola1") While oledbReader1.Read MsgBox("ola2") cod_qualitativa = oledbReader1.Item(0) MsgBox(cod_qualitativa) End While Finally End Try '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim sql3 As String = "Insert into apreciacao_global ([descr_apreci], [id_qualitativa]) values ('" & txtapreglobquali.Text & "', '" & cod_qualitativa & "') where ((avaliacao_qualitativa.id_qualitativa LIKE '%" & cod_qualitativa & "%'))" Dim cmd3 As New OleDbCommand(sql3, mydb) cmd3.ExecuteNonQuery() MsgBox("Apreciação global introduzida!") End Sub Edited June 6, 2012 at 02:50 PM by AnaGPSI Link to comment Share on other sites More sharing options...
ribeiro55 Posted June 6, 2012 at 02:54 PM Report Share #460912 Posted June 6, 2012 at 02:54 PM Lá em cima, do lado direito, não tens uma opção que sugira edição ao tópico? A síntaxe do INSERT não incluí WHERE. Não faz sentido. Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips" Link to comment Share on other sites More sharing options...
AnaGPSI Posted June 6, 2012 at 03:00 PM Author Report Share #460918 Posted June 6, 2012 at 03:00 PM Não só mesmo responder a tópico! Então como faço este meu insert? Já consegui thank you Link to comment Share on other sites More sharing options...
ribeiro55 Posted June 6, 2012 at 03:02 PM Report Share #460924 Posted June 6, 2012 at 03:02 PM Tira o WHERE. Não faz sentido, nem está previsto. Se tiveres de aplicar lógica para determinar quando e onde inserir, aplica-a antes, no client. Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips" 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