我正在尝试在第二个IF
条件或ElseIf
中读取我的数据库字段,但它似乎无法正常工作。这就像我试图验证某个学生是否在某个部分列表中具有相同的位置,或者某个学生已经在另一个部分列表中并且无法在其他部分列表中运行。
代码:
cmd.CommandText = " SELECT * FROM candidate WHERE cpos='" & ComboBox1.Text & "' AND cparty='" & ComboBox2.Text & "'"
dr = cmd.ExecuteReader
If dr.HasRows Then
MessageBox.Show("Position in that partylist already exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf dr("cfname") = TextBox2.Text And dr("cmname") = TextBox3.Text And dr("clname") = TextBox4.Text Then
MessageBox.Show("Student is currently in another partylist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
'Success'
Endif
更新
我做了类似这样的事情
cmd.CommandText = " SELECT * FROM candidate WHERE cpos='" & ComboBox1.Text & "' AND cparty='" & ComboBox2.Text & "'; SELECT * FROM candidate WHERE cfname='" & TextBox2.Text & "' AND cmname='" & TextBox3.Text & "' AND clname='" & TextBox4.Text & "' "
If dr.HasRows Then
MessageBox.Show("Position in that partylist already exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
dr.NextResult()
End If
If dr.HasRows Then
MessageBox.Show("Student is currently in another position", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
它的工作权利,但另一件事是当我触发第一个IF
和第二个IF
也触发时,我知道会发生但我不知道该怎么做,如果我'将第二个IF
变为ElseIf
然后它不会做我想做的事情。有什么提示吗?
答案 0 :(得分:0)
cmd.CommandText = " SELECT * FROM candidate WHERE cpos='" & ComboBox1.Text & "' AND cparty='" & ComboBox2.Text & "'; SELECT * FROM candidate WHERE cfname='" & TextBox2.Text & "' AND cmname='" & TextBox3.Text & "' AND clname='" & TextBox4.Text & "' "
这只是答案,哇!
If dr.HasRows Then
MessageBox.Show("Position in that partylist already exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIF dr.NexResult Then
MessageBox.Show("Student is currently in another position", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If