我正在使用Vb6!我有一个名为“Datagrid1”的数据网格,我从访问数据库的Datagrid1中的名为“subjectcode”的表中显示某些内容,如subjectname,subjectcode,theory_practical。
我还有一张名为“feedetail”的桌子。我怀疑的是,如果“理论 - 实践”价值是理论手段,那么它应该从名为feedetail的表中显示理论费,或者如果“theroy_practical”值是实用的手段,那么它应该在名为“费用”的新列中显示实际费用。 DataGrid1中。
我对sql语句感到困惑并在datagrid中显示!这是我用过的代码!
我想在Theory_Practical标题的下一栏中显示相应的费用!我无法附加截图文件,但显示错误! so here is the link of the screenshot file!提前致谢 !
Public con As New ADODB.Connection
Public rs As New ADODB.Recordset
Public rs2 As New ADODB.Recordset
Private Sub Command1_Click()
Dim semesternew As String
semesternew = semester.Caption
Select Case semesternew
Case "I"
semester1 = 1
Case "II"
semester1 = 2
Case "III"
semester1 = 3
Case "IV"
semester1 = 4
Case "V"
semester1 = 5
Case "VI"
semester1 = 6
End Select
DataGrid1.ClearFields
rs.Open "select Subjectcode,Subjectname,Theory_Practical from subjectcode as s where s.Degree='" & Degree & "' and s.Branch='" & course & "' and s.Year1='" & year1 & "' and s.Year2='" & year2 & "' and s.Semester='" & semester1 & "' ", con, 1, 3
Set DataGrid1.DataSource = rs
End Sub
Private Sub Command2_Click()
examfee2.Hide
examfee1.Show
End Sub
Private Sub Command4_Click()
If rs!Theory_Practical = "theory" Then
rs2.Open "select Theoryfee from Degreelevel", con, 1, 3
Set DataGrid2.DataSource = rs2
ElseIf rs!Theory_Practical = "practical" Then
rs2.Open "select Practicalfee from Degreelevel", con, 1, 3
Set DataGrid2.DataSource = rs2
End If
End Sub
Private Sub Form_Load()
Set con = New ADODB.Connection
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\college.mdb;Persist Security Info=False"
con.CursorLocation = adUseClient
Set rs = New ADODB.Recordset
End Sub
费用表:
Heading(Year1,Year2,Theoryfee,Practicalfee)
values (2001,2003,440,320)
所有其他值只有不同的值!
主题代码表:
Heading(Year1,Year2,Subjectcode,Subjectname,Theory_Practical)
values (2001,2003,RCCS10CS1,C programming, Theory)
答案 0 :(得分:0)
您可以使用如下查询:
SELECT subjectcode.Year1, subjectcode.Year2,
subjectcode.Subjectcode, subjectcode.Subjectname,
subjectcode.Theory_Practical, q.fee
FROM subjectcode
INNER JOIN (
SELECT fees.Year1, fees.Year2, "Theory" As FeeType,
fees.Theoryfee As Fee
FROM fees
UNION ALL
SELECT fees.Year1, fees.Year2, "Practical" As FeeType,
fees.Practicalfee As Fee
FROM fees) AS q
ON (subjectcode.Theory_Practical = q.FeeType)
AND (subjectcode.Year2 = q.Year2)
AND (subjectcode.Year1 = q.Year1)
但是,重新设计费用表以匹配内部sql返回的数据会更好,也就是说,理论和实际费用不同:
Year1 Year2 FeeType Fee
2001 2003 Theory 440
2001 2003 Practical 320