语句"SELECT SUM('totalprice') AS  总和 FROM equipment"一个button总价 数据显示在textbox内对sql语句转化到控件很陌生帮我写下吧

解决方案 »

  1.   


      private void GridViewBind()
        {
            string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            string SqlStr = "SELECT SUM('totalprice') AS  总和 FROM equipment";
            DataSet ds = new DataSet();
            SqlConnection conn = new SqlConnection(connStr);
            try
            {
                if (conn.State.ToString() == "Closed")
                    conn.Open();
                SqlDataAdapter da = new SqlDataAdapter(SqlStr, conn);
                da.Fill(ds);
                foreach(DataRow dr in ds.Table[0].DefultView)
                 {
                    this.textbox1.text=dr["总和"].Tostring()
                 }        }
            catch (Exception ex)
            {
                Response.Write("数据库错误,错误原因:" + ex.Message);
                Response.End();
            }
            finally
            {
                if (conn.State.ToString() == "Open")
                    conn.Close();
            }
        }
      

  2.   

                string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                SqlConnection conn=new SqlConnection(connStr);
                conn.Open();
                string sql="SELECT SUM('totalprice') AS  total FROM equipment";
                System.Data.SqlClient.SqlCommand cmd = new SqlCommand(sql, conn);
                TextBox1.Text=cmd.ExecuteScalar().ToString();
                cmd.Dispose();
                conn.Close();
                conn.Dispose();
      

  3.   

    private void GridViewBind()
        {
            string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            SqlConnection conn = new SqlConnection(connStr);
            SqlCommand cmd=new SqlCommand("SELECT SUM('totalprice') AS  总和 FROM equipment",conn);
            try
            {
                                this.textbox1.text=Convert.Tostring(cmd.ExecuteNonQuery());
                 }        }
            catch (Exception ex)
            {
                Response.Write("操作失败:原因是" + ex.Message);
                Response.End();
            }
            finally
            {
                if (conn.State.ToString() == "Open")
                    conn.Close();
            }
        }
      

  4.   

     SqlConnection conn=new SqlConnection();
       conn.ConnectionString=ConfigurationSettings.AppSettings["ConnectionString"];
        SqlCommand thisCommand = new SqlCommand("SELECT SUM('totalprice') AS  总和 FROM equipment", conn);
        thisCommand.CommandType = CommandType.Text;
     try
      {
         thisCommand.Connection.Open()
         SqlDataReader dr = thisCommand.ExecuteReader();
     while(dr.Read())
    {
     this.textbox1.text=dr["总和"].Tostring()}
     }
       catch(System.Data.SqlClient.SqlException ex)
       {
        MessageBox.Show(ex.Message);
       }
       finally
       {
        conn.Close();
       }
      

  5.   


    可以在页面放文本框 或是 用下拉框 让用户来输入或选择 地点 将选择的值作为条件  SELECT SUM('totalprice') AS  总和 FROM equipment where 地点=你选择的值
      

  6.   

    SELECT SUM('totalprice') AS  total FROM equipment where 地点字段='地点'