如何从数据库中汇总数据的大小 [英] How Can I sum Vales Of Data From Database

查看:107
本文介绍了如何从数据库中汇总数据的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

i有一个列名为Lot Number

的数据库,根据生产情况,批号下会有多个项目,如重量和日期。

所以这里我要总计相同批号的数据(值);

那么逻辑或代码是什么。

i已经完成了选择部分如

从(数据库)中选择(权重),其中lot_number ='+ textbox1.text +';

现在如何总结下的值相同的批号。

假设批号为1001

权重为; 100,1000,10000,2000,20000 .......... 2000等

hi everyone
i have an database with a column name Lot Number
and according to production there will be multiple Items under the Lot number like weight and date.
so here i want to sum the data (values) of the same Lot number;
so what will be the logic or code.
i have done the selecting part like
"select (weight)from (database) where lot_number='"+textbox1.text+"';
now how can i sum the values under the same lot number.
suppose for lot number 1001
weights are ;100,1000,10000,2000,20000 ..........2000 etc

推荐答案

嗨Shantanu,



它如此简单你可以尝试这个,简单而甜蜜; - )

Hi Shantanu,

Its so simple you can try this, simple and sweet ;-)
sqlCmd = "select SUM(weight) from ([database].tablename) where lot_number='"+textbox1.text+"';
      SqlCommand cmd = new SqlCommand(sqlCmd, conn);
 
       conn.Open();
 
       object resultResult = cmd.ExecuteScaler();
textbox2.text=totalResult.ToString();



希望这会对你有所帮助。



问候,

RK


Hope this helps you a bit.

Regards,
RK


你可以做,例如:

(产生一个总重量的行)对于给定的批号)

You can do, for instance:
(produces a row with total weight for given lot number)
select sum(weight) as tot_weight from database where lot_number=..









(产生许多行,报告所有批号的总重量。



or

(produces many rows, reporting the total weight of all the lot numbers)

select sum(weight) as tot_weight from database group by lot_number


你是我应该参考sql CRUD操作。



这是一个简单的查询。

You should refer sql CRUD operation.

This is the simple query.
Select sum(weights) from table where lot_number='"+textbox1.text+"'





您好,为此,您可以在datalogic中编写您的代码如下





Hi for that purpose you can write your code in datalogic as following

SqlConnection conn = new SqlConnection();
        conn.ConnectionString = ConfigurationManager.ConnectionStrings["connSpionshopString"].ConnectionString;
  
string sqlCmd = "Select sum(weights) as TotalWeight from table where lot_number='"+textbox1.text+"';";
       SqlCommand cmd = new SqlCommand(sqlCmd, conn);

       conn.Open();

       object value = cmd.ExecuteScaler();
        
textbox1.text=value.ToString();
       conn.Close();


这篇关于如何从数据库中汇总数据的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆