啥都不说了,求记录总数问题
以下是在Access中求记录总数的方法..
Set rsSort = Server.CreateObject( "ADODB.Recordset ")
strSQL = "* FROM tblSales " & _
" WHERE ProductCategoryID= " & CLng(intSelectedItem)
rsSort.Open strSQL,Conn,1,1
rc = rsSort.recordcount
rssort.Close
Set rssort = Nothing
If rc > 0 Then
Response.Write "对不起,此分类下还有 "& rc & "个小分类,不能删除! "
在SQL SERVER中应该怎么改啊?
------解决方案--------------------Set rsSort = Server.CreateObject( "ADODB.Recordset ")
strSQL = "SELECT * FROM tblSales " & _
" WHERE ProductCategoryID= " & CLng(intSelectedItem)
rsSort.Open strSQL,Conn,1,1
rc = rsSort.recordcount
rssort.Close
Set rssort = Nothing
If rc > 0 Then
Response.Write "对不起,此分类下还有 "& rc & "个小分类,不能删除! "
或
strSQL = "SELECT COUNT(*) FROM tblSales " & _
" WHERE ProductCategoryID= " & CLng(intSelectedItem)
Set Rs = Conn.Execute(strSQL)
If Rs(0) > 0 Then
Response.Write "对不起,此分类下还有 "& rc & "个小分类,不能删除! "
------解决方案--------------------SQL SERVER中很简单,不用程序判断,建立一个外建约束就行了,如果有小类的话,就会提示外建约束,删除失败
------解决方案--------------------您是刚学ASP吗?
<%
set conn = server.createobject( "adodb.connection ")
conn.open " " '数据库连接字付串.自己写全.
set rs = conn.execute( "select count(*) from 表 where .... ")
if not (rs.eof or rs.bof) then
intCount = rs(0)
else
intCount = 0
end if
rs.close : set rs = nothing
conn.close : set conn = nothing
%>
------解决方案--------------------照你的这段代码看,LIST应该是父类表,SORT是子类表了,你下面的这段代码除了少了删除子类表的记录外,没有什么问题,加上删除子类表记录的语句就可以了啊.
<%
Set rsSort = Server.CreateObject( "ADODB.Recordset ")
sqlsort= "SELECT * FROM Sort WHERE SortID = " & CLng(intSelectedItem)
rsSort.Open sqlsort,Conn,1,1
rc = rsSort.RecordCount
rssort.Close
Set rssort = Nothing
If rc > 0 Then
Response.Write "对不起,此分类下还有 "& rc & "个小分类,不能删除! "
Else
sqldelsoft= "DELETE FROM List WHERE SortID= "&CLng(intSelectedItem)
conn.Execute sqldelsoft
sqldelsoft= "DELETE FROM SORT WHERE SortID= "&CLng(intSelectedItem)
conn.Execute sqldelsoft
Response.Write "删除成功! "
End If
Application.Contents.RemoveAll()
CloseDb
%>