我尝试在表格中显示多个数据,我使用 INNER JOIN 来显示数据..
这是我显示这些数据的代码(在SQLYog中工作)
SELECT mahasiswa.NPM, mahasiswa.NamaMhs, mahasiswa.Jurusan,
mahasiswa.grup,mahasiswa.ta, bayar_lab.persen, bayar_dpp.persen
FROM bayar_dpp INNER JOIN bayar_lab ON bayar_dpp.NPM = bayar_lab.NPM
INNER JOIN mahasiswa ON bayar_lab.NPM = mahasiswa.NPM
ORDER BY mahasiswa.NPM
这是我在VB6上的代码,它将在VSFlexGrid上显示这些数据 注意:" TampilGrid"函数是执行我做的查询
Private Sub TampilGrid(ByVal SQLnya As String)
Grid.Rows = 1
Call AksesRS(SQLnya)
While Not rs.EOF
Grid.Rows = Grid.Rows + 1
Grid.TextMatrix(Grid.Rows - 1, 0) = rs.Fields(0)
Grid.TextMatrix(Grid.Rows - 1, 1) = rs.Fields(1)
Grid.TextMatrix(Grid.Rows - 1, 2) = rs.Fields(2)
Grid.TextMatrix(Grid.Rows - 1, 3) = rs.Fields(3)
Grid.TextMatrix(Grid.Rows - 1, 4) = rs.Fields(4)
lb_persendpp.Caption = Val(rs.Fields(5))
lb_persenlab.Caption = Val(rs.Fields(6))
rs.MoveNext
Wend
End Sub
但发生错误..显示
"在与请求对应的集合中找不到项目 name或ordinal",特别是在rs.Fields(3)中但是rs.Fields(0) 直到rs.Fields(2)没有错误
你能告诉我什么是错的吗?
答案 0 :(得分:0)
尝试使用最佳做法,
rs("empName")
。尝试以下代码。
Dim index as Integer
Grid.Rows = rs.RecordCount
index = 1
While Not rs.EOF
If Not IsNull(rs.Fields(0)) Then Grid.TextMatrix(index, 0) = rs.Fields(0)
If Not IsNull(rs.Fields(1)) Then Grid.TextMatrix(index, 1) = rs.Fields(1)
If Not IsNull(rs.Fields(2)) Then Grid.TextMatrix(index, 2) = rs.Fields(2)
If Not IsNull(rs.Fields(3)) Then Grid.TextMatrix(index, 3) = rs.Fields(3)
If Not IsNull(rs.Fields(4)) Then Grid.TextMatrix(index, 4) = rs.Fields(4)
If Not IsNull(rs.Fields(5)) Then lb_persendpp.Caption = Val(rs.Fields(5))
If Not IsNull(rs.Fields(6)) Then lb_persenlab.Caption = Val(rs.Fields(6))
index = index + 1
rs.MoveNext
Wend