how to display the datas in single line?

.net , asp.net Chile
  • 12 years ago
    I am using .net 2005.i am doing my project in asp.net.
    my project title is master log attendance.
    i want to display datas in single row for same name and id.
    i have 2 table named as attendance and employeedetails.

    The following code has worked very well.But datas are displayed in multiple row for same name and id.

    protected void img_submit_Click(object sender, ImageClickEventArgs e)
    {
    from_date = txt_fr_date.Text;
    to_date = txt_to_date.Text;
    emp_name = ddl_emp_name.SelectedValue;
    check();
    }
    void check()
    {

    System.TimeSpan dt_diff = Convert.ToDateTime(to_date).Subtract(Convert.ToDateTime(from_date));
    days = dt_diff.Days;


    dt.Columns.Add(new DataColumn("ID", typeof(string)));
    dt.Columns.Add(new DataColumn("Name", typeof(string)));


    for (int i = 0; i <= days; i++)

    {
    sql_date = Convert.ToDateTime(from_date).AddDays(i).ToString("MM/dd/yyyy");
    sql_date1 = Convert.ToDateTime(from_date).AddDays(i).ToString("MM/dd/yyyy");


    dt.Columns.Add(new DataColumn(sql_date1, typeof(string)));
    drow = dt.NewRow();

    com = new SqlCommand("select distinct rpt.emp_id as EmployeeID,card.username as EmployeeName,min(case when rpt.datetime1='" + sql_date + "' then rpt.datetime1 end) as '" + sql_date + "' from tbl_card as card,tbl_report as rpt where card.fkdata=rpt.emp_id and rpt.datetime1='" + sql_date + "' and emp_id='366' group by rpt.emp_id,card.username", con);
    dr = com.ExecuteReader();
    while (dr.Read())
    {
    drow[0] = dr.GetString(0);
    drow[1] = dr.GetString(1);

    drow[i+2] ="x";
    dt.Rows.Add(drow);
    }
    dr.Close();


    }



    GV_musterrole.DataSource = new DataView(dt);
    GV_musterrole.DataBind();

    }

    in above code,i applied query with groupby and distinct in for loop statement.
    using above code,the following output is coming in grid view,

    ID   Name  10/11/2007  10/12/2007 10/13/2007  10/14/2007 10/15/2007
    366  dinesh                       x
    366  dinesh                                         x
    366  dinesh                                                          x
    here 3 lines are displayed using for loop statement for same name and id.
    But I want to display in single line using for loop statement for same name and id as following output.How to do this?
    ID   Name  10/11/2007 10/12/2007 10/13/2007 10/14/2007 10/15/2007
    366 dinesh                        x               x               x

  • 12 years ago

     Have you tried this:

    instead of x use 1 for present 0 for absent and do a sum of your rows.

    You will then have only 1 row, and 1 each time the employee is present, 0 when they are absent

     

    Regards

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Every language has an optimization operator. In C++ that operator is ‘//’”