AnaGPSI Posted June 4, 2012 at 02:48 PM Report Share #460301 Posted June 4, 2012 at 02:48 PM Olá boa tarde tenho um problema no meu código: Ele não dá erro só que só me apresenta uma disciplina no DataGridView relacionada com esse aluno e ele na BD está associado a duas disciplinas alguém me consegue ajudar? O código é o seguinte: Private Sub apreciacao_global_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TextBox4.Text = avaliacoes.combonomecurso.Text TextBox1.Text = avaliacoes.comboturmavali.Text TextBox6.Text = avaliacoes.ComboBox7.Text TextBox11.Text = avaliacoes.TextBox1.Text TextBox33.Text = avaliacoes.TextBox3.Text TextBox2.Text = avaliacoes.TextBox2.Text 'Conexão com SQL 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) ''''''''''''''''''''''''''''''''''''''''''' Dim sql2 As String = "select * from curso where nome='" & TextBox4.Text & "'" Dim numeroprocesso As Integer = TextBox33.Text Dim oledbCnn As OleDbConnection Dim oledbCmd As OleDbCommand Dim cod_cur As Integer oledbCnn = New OleDbConnection(constr) Try oledbCnn.Open() oledbCmd = New OleDbCommand(sql2, oledbCnn) Dim oledbReader As OleDbDataReader = oledbCmd.ExecuteReader() While oledbReader.Read cod_cur = oledbReader.Item(0) 'MsgBox(cod_cur) End While 'Minha instrução SQL Dim VlSql1 As String = "SELECT disciplina.nome_disci as [Disciplina], avaliacao_qualitativa.conhecimentos as [Conhecimentos], avaliacao_qualitativa.iniciativa as [iniciativa], avaliacao_qualitativa.participacao as [Participação], avaliacao_qualitativa.concretizacao as [Concretização], avaliacao_qualitativa.organizacao as [Organização], avaliacao_qualitativa.evolucao as [Evolução] FROM (disciplina INNER JOIN avaliacao_qualitativa ON disciplina.cod_disciplina = avaliacao_qualitativa.cod_disciplina) INNER JOIN curso_disciplina ON disciplina.cod_disciplina = curso_disciplina.cod_disciplina WHERE ((curso_disciplina.cod_curso LIKE '%" & cod_cur & "%') AND (avaliacao_qualitativa.n_processo LIKE '%" & numeroprocesso & "%'))" Dim da1 As New OleDbDataAdapter(VlSql1, mydb) Dim dt1 As New Data.DataTable() Dim cmd1 As New OleDbCommand(VlSql1, mydb) Dim datacurso As OleDbDataReader = cmd1.ExecuteReader() 'Criando um datatable dt1 = New DataTable 'Passando o dados do dataadapter da1.Fill(dt1) 'Carregando o dados do datatable no DataGridView1 With DataGridView1 DataGridView1.DataSource = dt1 End With mydb.Close() oledbReader.Close() oledbCmd.Dispose() oledbCnn.Close() Catch ex As Exception 'MsgBox("Can not open connection ! ") End Try End Sub Link to comment Share on other sites More sharing options...
Caça Posted June 4, 2012 at 02:51 PM Report Share #460302 Posted June 4, 2012 at 02:51 PM Ou esta-te a falhar um Join ou esses Likes estão a pegar em mais registos que os que queres. Pedro Martins Não respondo a duvidas por PM Link to comment Share on other sites More sharing options...
AnaGPSI Posted June 4, 2012 at 02:58 PM Author Report Share #460306 Posted June 4, 2012 at 02:58 PM Eu fiz este select com a ajuda do access e lá apareciam-me as duas disciplinas! Link to comment Share on other sites More sharing options...
Caça Posted June 4, 2012 at 03:11 PM Report Share #460313 Posted June 4, 2012 at 03:11 PM Então vê qual é a query final e executa-a no Access Pedro Martins Não respondo a duvidas por PM Link to comment Share on other sites More sharing options...
AnaGPSI Posted June 4, 2012 at 03:12 PM Author Report Share #460314 Posted June 4, 2012 at 03:12 PM Como assim? Link to comment Share on other sites More sharing options...
Caça Posted June 4, 2012 at 03:15 PM Report Share #460316 Posted June 4, 2012 at 03:15 PM (edited) Quando o programa tiver a correr esse código, copia o conteúdo da variável VlSql1 executa-a no Access Edited June 4, 2012 at 03:15 PM by Caça Pedro Martins Não respondo a duvidas por PM Link to comment Share on other sites More sharing options...
AnaGPSI Posted June 4, 2012 at 03:15 PM Author Report Share #460317 Posted June 4, 2012 at 03:15 PM O select que tenho no codigo é o que fiz no access a unica coisa que troquei foi os criterios do access pelas variaveis finais no VB Link to comment Share on other sites More sharing options...
Caça Posted June 4, 2012 at 03:16 PM Report Share #460319 Posted June 4, 2012 at 03:16 PM E quem é que te garante que o problema não está ai? Testa e verifica. Pedro Martins Não respondo a duvidas por PM Link to comment Share on other sites More sharing options...
AnaGPSI Posted June 5, 2012 at 07:51 AM Author Report Share #460446 Posted June 5, 2012 at 07:51 AM (edited) Ao executar por linhas dá-me a sensação que ele não está a passar neste código: Try oledbCnn.Open() oledbCmd = New OleDbCommand(sql2, oledbCnn) Dim oledbReader As OleDbDataReader = oledbCmd.ExecuteReader() While oledbReader.Read cod_cur = oledbReader.Item(0) 'MsgBox(cod_cur) End While Realmente não está a passar, tirei agora a msgbox de comentado e nao aparece! Edited June 5, 2012 at 07:52 AM by AnaGPSI Link to comment Share on other sites More sharing options...
AnaGPSI Posted June 5, 2012 at 08:07 AM Author Report Share #460451 Posted June 5, 2012 at 08:07 AM Já me resolvi obrigada! 👍 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