请原谅我问,我的 if else 和 select case 语句只会转到 ELSE 选项。下面是我的代码
lblStudentName.Text = CStr(studentInfo.stuFullName)
lblStudentBirthCert.Text = CStr(studentInfo.birthCert)
Dim conn As New SqlConnection
Dim cmd As New SqlCommand
conn.ConnectionString = ("server = A-PC\SQLEXPRESS;database=studentManagement;integrated security=true")
conn.Open()
cmd.Connection = conn
cmd.Parameters.AddWithValue("@id", lblStudentBirthCert.Text)
cmd.CommandText = ("SELECT paymentType From payment Where birthcert=@id")
Dim reader As SqlDataReader = cmd.ExecuteReader()
Dim tempPaymentType As String
While reader.Read()
Dim tempPaymentType = reader.GetString(0)
Select Case tempPaymentType
Case "a"
txtFeeA.Text = tempPaymentType
Case "b"
txtFeeB.Text = tempPaymentType
Case "c"
txtFeeC.Text = tempPaymentType
Case "d"
txtFeeD.Text = tempPaymentType
Case "e"
txtFeeE.Text = tempPaymentType
Case Else
txtFeeF.Text = tempPaymentType
End Select
End While
reader.Close()
出于某种原因,它只会转到 else 并在 txtFeeF.text 中打印出来。查询将返回 6 个结果 btw,a 到 f。与 if else 语句相同。如果没有任何 if else 和 select 语句,输出将是 f,这是 reader 中的最后一个。任何帮助是极大的赞赏。
If tempPaymentType.Equals("a") Then
txtFeeA.Text = tempPaymentType.ToString
End If