select sum(size) as 变量名 from box where .......后在dataset中取回就好

解决方案 »

  1.   

    create procedure aa
    {
      @sum int output
    }
    asselect @sum=sum(size) from ...
    if @sum is null
      set @sum=0go
      

  2.   

    Dim FIRST_ID As String
            Session("USERID") = "s"
            FIRST_ID = Left(Session("USERID"), 1)
            Dim sqlConn As New SqlConnection(ConfigurationSettings.AppSettings("ConnStr"))
            Dim strSel As String = "select sum(size) as total from mailbox_body_" & FIRST_ID & " where newcheck = '1'"
            Dim cmd As SqlCommand = New SqlCommand(strSel, sqlConn)
            Dim dreader As SqlDataReader
            Dim i As Int16
            Try
                sqlConn.Open()
                dreader = cmd.ExecuteReader()
                While dreader.Read()
                    i = dreader("total")
                End While
                sqlConn.Close()
            Catch ex As Exception
                Page.RegisterStartupScript("alert", "<script language='javascript'> alert('网络不通或数据库连接错误') </script>")
                Exit Sub
            End Try
            sqlConn = Nothing
            cmd = Nothing
    我试过,不行
    to  hawise(清風) 
    你能说得详细点吗?
      

  3.   

    我将使用DataSet.
    String sqlstring= "select sum(size) as total from mailbox_body_" & FIRST_ID & " where newcheck = '1'"
    SqlConnection conn=new SqlConnection(...);
    SqlDataAdapter myAdapter=new SqlDataAdapter(sqlstring,conn);
    DataSet myDataSet=new DataSet();
    myAdapter.Fill(myDataSet,"tablename");
    Response.Write(myDataSet.Tables["tablename"].rows[0][total]);我没有时间试,你试一下看看。
      

  4.   

    select sum(size) as total from mailbox_body_ FIRST_ID  where newcheck = '1' group by newcheck
      

  5.   

    select count(*) as RecCount from Table
      

  6.   

    String sqlstring= "select sum(size) as total  from mailbox_body_s where newcheck = '1'";
    SqlConnection conn=new SqlConnection("....");
    SqlDataAdapter myAdapter=new SqlDataAdapter(sqlstring,conn);
    DataSet myDataSet=new DataSet();
    myAdapter.Fill(myDataSet,"mailbox_body_s");
    Response.Write(myDataSet.Tables["mailbox_body_s"].Rows[0]["total"]);
    方法可以,
    但要同时统计三列,该怎么写
    to hawise(清風) and all
      

  7.   

    to hawise(清風) and all
    但要同时统计三列,如size,num,count三列的值,结果分别放入
                      total,Tnum,Tcount 中
    该怎么写