conn.Execute "insert into studentclass(学号,课程号,成绩)" + _
"values('" + combostudentid.Text + _
"','" + txtclassid.Text + _
"','" + txtscore.Text + _
"')"
这是一条插入的SQL语句,现在要改变成:当选修某一课程(号)的学生超过20人时,就不能再选修了(也就不是插入了),应该如何改?谢谢
if (select count(distinct 学号) from studentclass where 课程号= 'txtclassid.Text' )<=20 then 上面的语句
else msgbox "error!"
这么可以吗?总发现在where语句那里出问题,那些引号啊真烦人!只剩14分了,呵呵!
"values('" + combostudentid.Text + _
"','" + txtclassid.Text + _
"','" + txtscore.Text + _
"')"
这是一条插入的SQL语句,现在要改变成:当选修某一课程(号)的学生超过20人时,就不能再选修了(也就不是插入了),应该如何改?谢谢
if (select count(distinct 学号) from studentclass where 课程号= 'txtclassid.Text' )<=20 then 上面的语句
else msgbox "error!"
这么可以吗?总发现在where语句那里出问题,那些引号啊真烦人!只剩14分了,呵呵!
rs.open "select count(distinct 学号) from studentclass where 课程号='" & txtclassid.Text & "'",conADOif rs(0)>20 then
......
else
msgbox "error"
end if
......
else
msgbox "error"
end if
当然不是!你在插入之前首先检查一下
Dim rsTemp As ADODB.Recordset
Dim intCount As Integer
Dim strSQL As String
strSQL = "select Count(课程号) from studentclass" _
& " where 课程号='" & txtclassid.Text & "'"
Set rsTemp = New ADODB.Recordset
rsTemp.Open strSQL, conn, adOpenStatic, adLockOptimistic
intCount = rsTemp(0)
rsTemp.Close
If intCount >= 20 Then
MsgBox "该课程的选修人数已达到最大,不能再选修!", vbInformation, "提示"
Exit Sub
End If '如果程序运行到这里,说明没有超过20个人,就可以添加了。
conn.Execute "insert into studentclass(学号,课程号,成绩)" + _
"values('" + combostudentid.Text + _
"','" + txtclassid.Text + _
"','" + txtscore.Text + _
"')"
strSQL = "select Count(学号) from studentclass" _
& " where 课程号='" & txtclassid.Text & "'"
个人意见!