protected void Page_Load(object sender, EventArgs e) 
    {         if (!this.Page.IsPostBack) 
        { 
          string v7; 
            SqlCommand cmd = new SqlCommand(); 
            
            SqlConnection con = new SqlConnection("Server=(local);user id=sa;pwd=;database=master"); 
            con.Open(); 
            SqlDataAdapter ap = new SqlDataAdapter("select sum(expend) from account_bill",con); 
            v7 = ap; 
            this.label.Text =v7; 
            con.Close();         } 
提示错误: 错误 1 无法将类型“System.Data.SqlClient.SqlDataAdapter”隐式转换为“string” 

解决方案 »

  1.   

    string v7;
                SqlCommand cmd = new SqlCommand();            SqlConnection con = new SqlConnection("Server=(local);user id=sa;pwd=;database=master");
                con.Open();
                SqlDataAdapter ap = new SqlDataAdapter("select sum(expend) from account_bill", con);
                DataTable dt = new DataTable();
                ap.Fill(dt);
                if (dt != null && dt.Rows.Count > 0)
                {
                    v7 = dt.Rows[0][0].ToString();
                }
                con.Close();
      

  2.   

    [code=BatchFile]string sql="select sum(expend) from account_bill;
    SqlCommand cmd = new SqlCommand(sql, con);
    con.Open(); 
    string v7 = cmd.ExecuteScalar();
    this.label.Text =v7; 
    con.Close[/code]
    楼主有点复杂化问题了
      

  3.   

    string v7; 
                SqlCommand cmd = new SqlCommand(); 
                
                SqlConnection con = new SqlConnection("Server=(local);user id=sa;pwd=;database=master"); 
                con.Open(); 
                SqlDataAdapter ap = new SqlDataAdapter("select sum(expend) from account_bill",con); 
                v7 = ap; 
                this.label.Text =v7; 
                con.Close(); 
    这也能赋值?找基础的书看看先吧
      

  4.   

    改好了,但是有一个错误:protected void Page_Load(object sender, EventArgs e)
        {        if (!this.Page.IsPostBack)
            {
                SqlConnection con = new SqlConnection("Server=(local);user id=sa;pwd=;database=master");
                string sql="select sum(expend) from account_bill";
                SqlCommand cmd = new SqlCommand(sql,con);
                con.Open();
                string v7 = cmd.ExecuteScalar();
                this.label.Text = v7;
                con.Close();        }
        }错误 1 无法将类型“object”隐式转换为“string”
      

  5.   


    非常感谢shadowjl !感谢各位!
      

  6.   

    楼主多看看书,顺便结贴。protected void Page_Load(object sender, EventArgs e) 
        {         if (!this.Page.IsPostBack) 
            { 
              string v7; 
                SqlCommand cmd = new SqlCommand(); 
                
                SqlConnection con = new SqlConnection("Server=(local);user id=sa;pwd=;database=master"); 
                con.Open(); 
                cmd.CommandText="select sum(expend) from account_bill";
                cmd.Connection=con;
                             v7 = cmd.ExecuteScalar().ToString(); 
                this.label.Text =v7; 
                con.Close();         }