请教一下,在c#,查询数据表后的内容,各行数据中,若有其中几项(产品名称、批号、工序)相同时,则将这些符合条件行的数据,之前的累积产量 + 当天产量的合计结果,做为当天的累积产量,请问这个怎么实现;
代码如下,需要通过foreach循环查询dt吧,查询的内容,若是这几项相同,则累积数量进行累加,方便请给完善一下代码,谢谢;
private void btnquery_Click(object sender, EventArgs e)
{
conn = new SqlConnection("server= 192.168.100.247; database= Whmesinfo;User= Sa;Password=whyy@2021");
conn.Open();
//sqlstring = "select * from w_prohourcount where isnull(process,'') like '%" + comprocess.Text + "%'and isnull(proname,'') like '%"
//+ comproduct.Text + "%' and isnull(batchNo,'') like '%" + batchNo.Text + "%'and [date] <= '"
//+ dateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:ss") + "'order by date asc";
sqlstring = @"select * from w_prohourcount where isnull(batchNo,'') like '%" + batchNo.Text
+ "%' and isnull(process,'') like '%" + comprocess.Text + "%' and isnull(proname,'') like '%" + comproduct.Text + "%' and [date] <= '"
+ dateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:ss") + "'order by date desc";
try
{
SqlCommand cmd = new SqlCommand(sqlstring, conn);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds, "w_prohourcount");
dt = ds.Tables["w_prohourcount"];
dataGridView1.DataSource = dt.DefaultView;
this.dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dataGridView1.Columns[0].Visible = false;
dataGridView1.Columns[1].HeaderText = "日期";
dataGridView1.Columns[2].HeaderText = "车间";
dataGridView1.Columns[3].HeaderText = "班组";
dataGridView1.Columns[4].HeaderText = "班次";
dataGridView1.Columns[5].HeaderText = "工序";
dataGridView1.Columns[6].HeaderText = "批号";
dataGridView1.Columns[7].HeaderText = "产品批号";
dataGridView1.Columns[8].HeaderText = "产品名称";
dataGridView1.Columns[9].HeaderText = "规格";
dataGridView1.Columns[10].HeaderText = "单位";
dataGridView1.Columns[11].HeaderText = "当日产量";
dataGridView1.Columns[12].HeaderText = "累积产量";
dataGridView1.Columns[13].HeaderText = "完工状态";
dataGridView1.Columns[14].HeaderText = "人数";
dataGridView1.Columns[15].HeaderText = "工时";
dataGridView1.Columns[16].HeaderText = "备注";
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//点击该行,即全选该行;
dataGridView1.AutoGenerateColumns = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally { conn.Close(); }
}