如何把sql,累加后数值,绑定在c#的label控件上?显示该数值 SqlConnection conn = new SqlConnection(connString); SqlDataAdapter sda = new SqlDataAdapter("select foodname,foodsum,foodallprice,waitername,beizhu,zhuotai,datatime from tb_GuestFood where zhuotai='" + names + "' order by ID desc compute sum(foodallprice)", conn); DataSet ds = new DataSet(); sda.Fill(ds); conn.Open(); string time = dgvRecord[6, rowID].Value.ToString(); lblLeftJdsj.Text = time; lblLeftXfje.Text =??????;
如何把“SUM”的数值,绑定在c#的label( lblLeftXfje)控件上?
------解决方案-------------------- 加一个输出参数@sum,将sum的值放在@sum中
------解决方案-------------------- "select foodname,foodsum,sum(foodallprice)as s,waitername,beizhu,zhuotai,datatime from tb_GuestFood where zhuotai='" + names + "' group by foodname, foodsum, waitername,beizhu,zhuotai,datatime order by ID desc"
lblLeftXfje.Text = FileName('s'); ? 是这样吗?
坐等高手现身
------解决方案-------------------- order by ID desc compute sum(foodallprice这个order by 会出错,都没加逗号啊。
select sum(某字段) as tmp ... lblLeftXfje.Text = ds.Tables[0].Rows[0,"tmp"].toSring();
------解决方案-------------------- SQL语句没问题的!