The problem is that this returns me 8 records while in the database they are only 2. That is 4 for each 1. I can not understand why. (If you want to edit the title of the question)
I have this DB:
AndIhavethisselect:
selectalunos.numero,faltas_licao.tipofromturma,alunos,disciplinas,licao,faltas_licaowherefaltas_licao.aluno_id=alunos.id_alunoandlicao.id_turma=turma.id_turmaandfaltas_licao.id_disciplina=licao.id_disciplinaandlicao.id_disciplina=disciplinas.id_disciplinaandfaltas_licao.licao='" & currentlicao & "'
and disciplinas.nome = '" & F_Topo.CB_Disciplina.SelectedItem.ToString & "'
and turma.nome = '" & F_Topo.CB_Turma.SelectedItem.ToString & "'
and alunos.Numero = '" & aluno & "'"
Here is the "all" code:
Dim con3 As New SqlConnection(cs)
Dim currentlicao As Integer = get_licao()
'MsgBox("current: " & currentlicao)
Using con3
Dim aluno As Integer = linha.Index
Dim sql As String = "select alunos.numero,faltas_licao.tipo from turma,alunos,disciplinas,licao,faltas_licao where faltas_licao.aluno_id = alunos.id_aluno and licao.id_turma = turma.id_turma and faltas_licao.id_disciplina = licao.id_disciplina and licao.id_disciplina = disciplinas.id_disciplina and faltas_licao.licao = '" & currentlicao & "' and disciplinas.nome = '" & F_Topo.CB_Disciplina.SelectedItem.ToString & "' and turma.nome = '" & F_Topo.CB_Turma.SelectedItem.ToString & "' and alunos.Numero = '" & aluno & "'"
'MsgBox(sql)
Dim sqlCom As New SqlCommand(sql, con3)
con3.Open()
Dim dr3 As SqlDataReader = sqlCom.ExecuteReader()
Dim miau As Integer = 0
If dr3.HasRows Then
While dr3.Read()
miau = miau + 1
'F_Principal.DataGridView2.Rows.Add(F_Principal.DataGridView2.RowCount + 1, dr3.Item(0))
MsgBox(miau)
MsgBox("ID: " & dr3.Item(0) & "TIPO:" & dr3.Item(1))
End While
Else
' Aqui faça o que quiser caso não tenha linha '
End If
dr3.Close()
Data in the database:
Idonotunderstandhowitreturnsmefourrecords(aka8records,4beingrepeated).
Cananyonewithdatabaseexperiencespottheerror?
EDIT:
Error:
System.Data.SqlClient.SqlException(0x80131904):Theobjects"missing_licao" and "missing_licao" in the FROM clause have the same exposed names. Use correlation names to distinguish them. in System.Data.SqlClient.SqlConnection.OnError (SqlException exception, Boolean breakConnection, Action% with% 1 wrapCloseInAction) in System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning (TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) in System.Data.SqlClient.TdsParser.TryRun (RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean & dataReady) in System.Data.SqlClient.SqlDataReader.TryConsumeMetaData () in System.Data.SqlClient.SqlDataReader.get_MetaData () in System.Data.SqlClient.SqlCommand.FinishExecuteReader (SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) in System.Data.SqlClient.SqlCommand.RunExecuteReaderTds (CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task & Task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest) in System.Data.SqlClient.SqlCommand.RunExecuteReader (CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task & Task, Boolean asyncWrite) in System.Data.SqlClient.SqlCommand.RunExecuteReader (CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) in System.Data.SqlClient.SqlCommand.ExecuteReader (CommandBehavior behavior, String method) in System.Data.SqlClient.SqlCommand.ExecuteReader () in Work_mod_16.F_Contentor.get_falls () in C: \ Users \ AlunoP \ Desktop \ Job modulo 16 \ Job mod 16 \ Job mod 16 \ F_Contentor.vb: line 163 ClientConnectionId: 03d47535-a3d9-4723-b704-2649901d693e Error Number: 1013, State: 1, Class: 16