0

我正在使用 Vb6 !我有一个名为“Datagrid1”的数据网格,我从访问数据库的 Datagrid1 中名为“subjectcode”的表中显示某些内容,例如主题名、主题代码、理论实用。

我还有另一个名为“feedetail”的表。我的疑问是,如果“theory_practical”值是理论值,那么它应该显示名为 feedetail 的表中的理论费,或者如果“theroy_practical”值是实际值,那么它应该在名为“Fee”的新列中显示实际费用数据网格1。

我对 sql 语句和在 datagrid 中显示感到困惑!这是我使用的代码!

我想在 Theory_Practical 标题的下一栏中显示相应的费用!我无法附加屏幕截图文件,它显示错误!所以这里是截图文件的链接!提前致谢 !

    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) 
4

1 回答 1

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
于 2013-01-14T13:25:36.387 回答