AnaGPSI Posted May 28, 2012 at 12:42 PM Report #458493 Posted May 28, 2012 at 12:42 PM (edited) Ola boa tarde. Tenho um problema no seguinte bocado de código: Dim text3 As Integer = oledbReader1.Item(26) Dim oledbCnn4 As OleDbConnection Dim oledbCmd4 As OleDbCommand Dim sqlc As String = "Select * from encarregado_educacao where cod_ee = " & text3 & "" oledbCnn4 = New OleDbConnection(connetionString) oledbCnn4.Open() oledbCmd4 = New OleDbCommand(sqlc, oledbCnn4) Dim oledbReader4 As OleDbDataReader = oledbCmd4.ExecuteReader() While oledbReader4.Read combonomeEE.Text = oledbReader4.Item(1) 'MsgBox(oledbReader4.Item(1)) teleEE.Text = oledbReader4.Item(2) 'MsgBox(oledbReader4.Item(2)) txtmoradaEE.Text = oledbReader4.Item(3) profEE.Text = oledbReader4.Item(4) ' MsgBox(oledbReader4.Item(4)) ComboBox2.Text = oledbReader4.Item(5) comboempEE.Text = oledbReader4.Item(6) Dim postal3 As String = oledbReader4.Item(7) Dim postal4, postal5 As String 'postal3 postal4 = postal3.Substring(0, 4) 'MsgBox(postal4) 'postal5 postal5 = postal3.Substring(5) 'MsgBox(postal5) txtcodpostEE1.Text = postal4 txtcodpostEE2.Text = postal5 txtlocaliEE.Text = oledbReader4.Item(8) ComboBox1.Text = oledbReader4.Item(9) End While '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' End While Ao clicar no botão preenche-me todos os campos com os dados relativos a um n_processo ou aluno. No formulário vai buscar tambem os dados do encarregado de educação do aluno em questão. O problema é que na tabpage do encarregado de educação preenche quase todos os campos menos o nome, o numero de telemovel e a profissao, se voltar a carregar no botão com o mesmo nome ou n_processo preenche esses campos em falta. Alguém saberá como posso resolver este problema? Edited May 28, 2012 at 12:50 PM by Caça GeSHi
Caça Posted May 28, 2012 at 12:54 PM Report #458497 Posted May 28, 2012 at 12:54 PM Provavelmente não está a entrar nesse código. Pedro Martins Não respondo a duvidas por PM
AnaGPSI Posted May 28, 2012 at 01:05 PM Author Report #458503 Posted May 28, 2012 at 01:05 PM Ele só não me preenche estes campos: combonomeEE.Text = oledbReader4.Item(1) 'MsgBox(oledbReader4.Item(1)) teleEE.Text = oledbReader4.Item(2) 'MsgBox(oledbReader4.Item(2)) profEE.Text = oledbReader4.Item(4) ' MsgBox(oledbReader4.Item(4)) tudo o resto preenche.
Caça Posted May 28, 2012 at 01:08 PM Report #458504 Posted May 28, 2012 at 01:08 PM E existe valores nessas posições? Não os estás a limpar mais abaixo? Pedro Martins Não respondo a duvidas por PM
AnaGPSI Posted May 28, 2012 at 01:10 PM Author Report #458507 Posted May 28, 2012 at 01:10 PM Não até porque quando carrego na botão para que me preencha os dados as msgbox dos respectivos campos dão o nome correto.
Caça Posted May 28, 2012 at 01:20 PM Report #458509 Posted May 28, 2012 at 01:20 PM Então deves estar a limpa-las mais em baixo.. Pedro Martins Não respondo a duvidas por PM
Caça Posted May 28, 2012 at 01:30 PM Report #458511 Posted May 28, 2012 at 01:30 PM Alguma coisa tens de estar a fazer.. Coloca um breakpoint numa dessas textboxes para verificar se elas quando estás a ir buscar os dados estão a assumir algum valor. Pedro Martins Não respondo a duvidas por PM
AnaGPSI Posted May 28, 2012 at 01:50 PM Author Report #458514 Posted May 28, 2012 at 01:50 PM (edited) Já experimentei e estão a assumir o valor correto (o mesmo valor que me devolvem as msgbox) Aqui vai o código do botão todo. Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Dim connetionString As String Dim oledbCnn1 As OleDbConnection Dim oledbCmd1 As OleDbCommand 'Conexão com SQL connetionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\GPSI\Documents\mydb.accdb;" Dim mydb As New OleDbConnection(connetionString) ' mydb.Open() 'MsgBox("State: " & mydb.State.ToString(), ' MsgBoxStyle.Information) ''''''''''''''''''''''''''''''''''''''''''' Dim text As String = txtprocesso.Text Dim numi As Integer = CInt(text) Dim sql As String = "Select * from aluno where n_processo = " & numi & "" oledbCnn1 = New OleDbConnection(connetionString) oledbCnn1.Open() oledbCmd1 = New OleDbCommand(sql, oledbCnn1) Dim oledbReader1 As OleDbDataReader = oledbCmd1.ExecuteReader() txtprocesso.Clear() While oledbReader1.Read txtprocesso.Text = oledbReader1.Item(0) txtnomealuno1.Text = oledbReader1.Item(1) txtnomealuno2.Text = oledbReader1.Item(1) combosexo.Text = oledbReader1.Item(2) datatimenascialuno.Text = oledbReader1.Item(3) txtbi.Text = oledbReader1.Item(4) databi.Text = oledbReader1.Item(5) txtanotaluno.Text = oledbReader1.Item(6) txtmoradaluno.Text = oledbReader1.Item(7) Dim postal As String = oledbReader1.Item(8) Dim postal1, postal2 As String 'postal1 postal1 = postal.Substring(0, 4) 'MsgBox(postal1) 'postal2 postal2 = postal.Substring(5) 'MsgBox(postal2) txtcodpostaluno1.Text = postal1 txtcodpostaluno2.Text = postal2 TextBox2.Text = oledbReader1.Item(9) txtocorraluno.Text = oledbReader1.Item(10) txtmedicoaluno.Text = oledbReader1.Item(11) datatimevacina.Text = oledbReader1.Item(12) TextBox3.Text = oledbReader1.Item(13) TextBox4.Text = oledbReader1.Item(14) combofami.Text = oledbReader1.Item(15) txtlocalidadealuo.Text = oledbReader1.Item(16) txtemailaluno.Text = oledbReader1.Item(17) txtfregnataluno.Text = oledbReader1.Item(18) txtconcnataluno.Text = oledbReader1.Item(19) txtpaisnataluno.Text = oledbReader1.Item(20) txtdistriresialuno.Text = oledbReader1.Item(21) txtconcresialuno.Text = oledbReader1.Item(22) txtfregresialuno.Text = oledbReader1.Item(23) ComboBox3.Text = oledbReader1.Item(24) txtnacialuno.Text = oledbReader1.Item(28) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim text1 As Integer = oledbReader1.Item(24) Dim oledbCnn2 As OleDbConnection Dim oledbCmd2 As OleDbCommand Dim sqla As String = "Select * from turma where cod_turma = " & text1 & "" oledbCnn2 = New OleDbConnection(connetionString) oledbCnn2.Open() oledbCmd2 = New OleDbCommand(sqla, oledbCnn2) Dim oledbReader2 As OleDbDataReader = oledbCmd2.ExecuteReader() While oledbReader2.Read ComboBox3.Text = oledbReader2.Item(2) End While '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim text2 As Integer = oledbReader1.Item(27) Dim oledbCnn3 As OleDbConnection Dim oledbCmd3 As OleDbCommand Dim sqlb As String = "Select * from filiacao where cod_filiacao = " & text2 & "" oledbCnn3 = New OleDbConnection(connetionString) oledbCnn3.Open() oledbCmd3 = New OleDbCommand(sqlb, oledbCnn3) Dim oledbReader3 As OleDbDataReader = oledbCmd3.ExecuteReader() While oledbReader3.Read txtnomepai.Text = oledbReader3.Item(1) txtnomemae.Text = oledbReader3.Item(2) txtprofpai.Text = oledbReader3.Item(3) txtprofmae.Text = oledbReader3.Item(4) comboemppai.Text = oledbReader3.Item(5) comboempmae.Text = oledbReader3.Item(6) comboformpai.Text = oledbReader3.Item(7) comboformmae.Text = oledbReader3.Item(8) txttelepai.Text = oledbReader3.Item(9) txttelemae.Text = oledbReader3.Item(10) End While '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim text3 As Integer = oledbReader1.Item(26) Dim oledbCnn4 As OleDbConnection Dim oledbCmd4 As OleDbCommand Dim sqlc As String = "Select * from encarregado_educacao where cod_ee = " & text3 & "" oledbCnn4 = New OleDbConnection(connetionString) oledbCnn4.Open() oledbCmd4 = New OleDbCommand(sqlc, oledbCnn4) Dim oledbReader4 As OleDbDataReader = oledbCmd4.ExecuteReader() While oledbReader4.Read combonomeEE.Text = oledbReader4.Item(1) 'MsgBox(oledbReader4.Item(1)) teleEE.Text = oledbReader4.Item(2) 'MsgBox(oledbReader4.Item(2)) txtmoradaEE.Text = oledbReader4.Item(3) profEE.Text = oledbReader4.Item(4) ' MsgBox(oledbReader4.Item(4)) ComboBox2.Text = oledbReader4.Item(5) comboempEE.Text = oledbReader4.Item(6) Dim postal3 As String = oledbReader4.Item(7) Dim postal4, postal5 As String 'postal3 postal4 = postal3.Substring(0, 4) 'MsgBox(postal4) 'postal5 postal5 = postal3.Substring(5) 'MsgBox(postal5) txtcodpostEE1.Text = postal4 txtcodpostEE2.Text = postal5 txtlocaliEE.Text = oledbReader4.Item(8) ComboBox1.Text = oledbReader4.Item(9) End While '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' End While End Sub Edited May 28, 2012 at 01:53 PM by Caça GeSHi
Caça Posted May 28, 2012 at 01:54 PM Report #458516 Posted May 28, 2012 at 01:54 PM Tens bindings nessas TextBoxes? Pedro Martins Não respondo a duvidas por PM
AnaGPSI Posted May 28, 2012 at 01:56 PM Author Report #458518 Posted May 28, 2012 at 01:56 PM Bindings como assim?
Caça Posted May 28, 2012 at 02:08 PM Report #458524 Posted May 28, 2012 at 02:08 PM Se por exemplo, a propriedade Text de uma dessas TextBoxes está associada a uma fonte de dados(DataSet, Classes, etc..) Pedro Martins Não respondo a duvidas por PM
AnaGPSI Posted May 28, 2012 at 02:14 PM Author Report #458527 Posted May 28, 2012 at 02:14 PM Não tenho nada disso!
Caça Posted May 28, 2012 at 02:16 PM Report #458528 Posted May 28, 2012 at 02:16 PM Estas a utilizar algum evento como por exemplo o SelectedIndexChanged para alguma destas ComboBoxes? combonomeEE ComboBox2 comboempEE ComboBox1 O mesmo para estas TextBoxes teleEE profEE txtcodpostEE1 txtcodpostEE2 txtlocaliEE Se sim mostra o código. Pedro Martins Não respondo a duvidas por PM
AnaGPSI Posted May 28, 2012 at 02:24 PM Author Report #458531 Posted May 28, 2012 at 02:24 PM (edited) Estou a utilizar na combobox1 para seleccionar o parentesco. Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged If ComboBox1.Text = "Mãe" Then combonomeEE.Text = txtnomemae.Text profEE.Text = txtprofmae.Text teleEE.Text = txttelemae.Text ComboBox2.Text = comboformmae.Text comboempEE.Text = comboempmae.Text End If If ComboBox1.Text = "Pai" Then combonomeEE.Text = txtnomepai.Text profEE.Text = txtprofpai.Text teleEE.Text = txttelepai.Text ComboBox2.Text = comboformpai.Text comboempEE.Text = comboemppai.Text End If If ComboBox1.Text = "Outro" Then combonomeEE.Text = "" profEE.Text = "" teleEE.Text = "" ComboBox2.Text = "" comboempEE.Text = "" End If End Sub Edited May 28, 2012 at 02:34 PM by Caça GeSHi
Caça Posted May 28, 2012 at 02:34 PM Report #458534 Posted May 28, 2012 at 02:34 PM Então o problema deve estar ai, ele não está a disparar logo o evento.. Experimenta preencher essa combobox logo na primeira linha desse While oledbReader4.Read Pedro Martins Não respondo a duvidas por PM
AnaGPSI Posted May 28, 2012 at 02:41 PM Author Report #458541 Posted May 28, 2012 at 02:41 PM Não entendi! Mas eu acho que é isso que estou a fazer. A comobobox parentesco (combobox1) é preenchida no formulário. P.S. o nome combonomeEE é uma textbox alterei o nome devido a uns problemas que ja tive antes e foi para experimentar mas mesmo assim dá o mesmo problema.
Caça Posted May 28, 2012 at 02:45 PM Report #458546 Posted May 28, 2012 at 02:45 PM Exprimenta comentar esse código que está no evento da combobox e correr para ver se funciona. Pedro Martins Não respondo a duvidas por PM
AnaGPSI Posted May 28, 2012 at 02:47 PM Author Report #458548 Posted May 28, 2012 at 02:47 PM Com ele em comentado já dá!
Caça Posted May 28, 2012 at 02:49 PM Report #458551 Posted May 28, 2012 at 02:49 PM Então tens de fazer ai uma verificação. Pedro Martins Não respondo a duvidas por PM
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