获取具有相同id但不同值的行,并在不同的标签asp.net中显示不同的值

时间:2017-04-20 01:52:13

标签: c# asp.net

这项工作但我希望显示值是否存在,因此用户可以根据每个process_id在每个标签中看到值username和last_update,但它们具有相同的request_id。此代码仅显示基于用户名登录的用户名和last_update。我可以这样做吗?

 using(SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["MESTrans"].ConnectionString))
        {
            //bool exists = false;
            int exists;
            con.Open();

                foreach (GridViewRow row in GridView2.Rows)
                {

                    int req_id = Convert.ToInt32(GridView2.DataKeys[row.RowIndex].Values[0]);
                    using (SqlCommand cmd = new SqlCommand("select count(*) from [CutPanelConfirmation] where req_id=@req_id and process_id=@process_id", con))
                    {
                        cmd.Parameters.AddWithValue("@process_id", Session["process_id"].ToString());
                        cmd.Parameters.AddWithValue("@req_id", req_id);
                        exists = (int)cmd.ExecuteScalar();
                    }
                    if (exists > 0)
                    {
                        query = "select * from CutPanelConfirmation where req_id=@req_id and process_id=@process_id";
                        cmd = new SqlCommand(query, con);
                        cmd.Parameters.AddWithValue("@process_id", Session["process_id"].ToString());
                        cmd.Parameters.AddWithValue("@req_id", req_id);
                        SqlDataReader dr = cmd.ExecuteReader();

                       while (dr.Read())
                        {

                            if ((string)dr["process_id"] == "marker")
                            {

                                LabelNameMarker.Text = LabelNameMarker.Text + " " + dr[1].ToString();
                                LabelDateMarker.Text = LabelDateMarker.Text + " " + dr[3].ToString();

                            }
                            if ((string)dr["process_id"] == "fabric")
                            {
                                LabelNameFabric.Text = LabelNameFabric.Text + " " + dr[1].ToString();
                                LabelDateFabric.Text = LabelDateFabric.Text + " " + dr[3].ToString();
                            }
                            if ((string)dr["process_id"] == "cutting")
                            {
                                LabelNameCutting.Text = LabelNameCutting.Text + " " + dr[1].ToString();
                                LabelDateCutting.Text = LabelDateCutting.Text + " " + dr[3].ToString();
                            }
                            if ((string)dr["process_id"] == "SPP")
                            {
                                LabelNameSPP.Text = LabelNameSPP.Text + " " + dr[1].ToString();
                                LabelDateSPP.Text = LabelDateSPP.Text + " " + dr[3].ToString();
                            }
                            if ((string)dr["process_id"] == "kitting")
                            {
                                LabelNameKitting.Text = LabelNameKitting.Text + " " + dr[1].ToString();
                                LabelDateKitting.Text = LabelDateKitting.Text + " " + dr[3].ToString();
                            }
                            if ((string)dr["process_id"] == "sew")
                            {
                                LabelNameSew.Text = LabelNameSew.Text + " " + dr[1].ToString();
                                LabelDateSew.Text = LabelDateSew.Text + " " + dr[3].ToString();
                            }

                        }
                        dr.Close();

                    }

                con.Close();
            }
        }

1 个答案:

答案 0 :(得分:0)

发布[https://stackoverflow.com/users/7892938/nfh][NFH]答案 我只是从此查询中删除@进程ID,它按我的要求工作! :

query = "select * from CutPanelConfirmation where req_id=@req_id and process_id=@process_id"; cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@process_id", Session["process_id"].ToString()); cmd.Parameters.AddWithValue("@req_id", req_id); SqlDataReader dr = cmd.ExecuteReader();