Click here to Skip to main content
15,112,198 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to add attendance condition on runtime in datagridview.. for example if time is <= 09:45:00 then show present else if time is null then show absent in P/A column and then add in database using datagridview windows form c#




image ( https://i.stack.imgur.com/SdF5d.png )

What I have tried:

   try
{
              SqlCommand ucd = new SqlCommand("indiviual_attendence", ConnectionString.Getconnection());
              ucd.CommandType = CommandType.StoredProcedure;
              ucd.Parameters.Add("@id", SqlDbType.Int).Value = 2;
              ucd.Parameters.Add("@empcode", SqlDbType.NVarChar).Value = value;
              SqlDataAdapter sda = new SqlDataAdapter(ucd);
              dt = new DataTable();
              sda.Fill(dt);
              if (dt.Rows.Count > 0)
              {
                  textBox2.Text = dt.Rows[0][0].ToString();
              }
              ConnectionString.closeconnection();
              if (textBox2.Text != "")
              {
                  cmd = new SqlCommand("indiviual_attendence", ConnectionString.Getconnection());
                              cmd.CommandType = CommandType.StoredProcedure;
                             cmd.Parameters.Add("@id",SqlDbType.Int).Value = 3;
                             cmd.Parameters.Add("@empcode",SqlDbType.NVarChar).Value = "%"+value;
                  SqlDataAdapter sd = new SqlDataAdapter(cmd);
                  dt = new DataTable();
                  sd.Fill(dt);
                  if (dt.Rows.Count > 0)
                  {
                      dataGridView1.DataSource = dt;
                      dataGridView1.Columns[0].HeaderText = "Code";
                      dataGridView1.Columns[1].HeaderText = "Name";
                      dataGridView1.Columns[2].HeaderText = "Department";
                      dataGridView1.Columns[3].HeaderText = "Year";
                      dataGridView1.Columns[4].HeaderText = "Month";
                      dataGridView1.Columns[5].HeaderText = "Day";
                      dataGridView1.Columns[6].HeaderText = "Time";
                      dataGridView1.Columns[7].HeaderText = "Status";
                      dataGridView1.Columns[8].HeaderText = "EMP/MACH-CODE";  
                      dataGridView1.Columns[9].HeaderText = "Attendance_id";
                      dataGridView1.Columns[9].Visible = false;
                     dataGridView1.Columns[10].HeaderText = "P/A";
                     // dataGridView1.Columns["Attendance_id"].Visible = false;
                      dataGridView1.AllowUserToAddRows = false;
                      dataGridView1.AllowUserToResizeColumns = false;
                      dataGridView1.BackgroundColor = System.Drawing.SystemColors.Control;
                      this.dataGridView1.DefaultCellStyle.BackColor = Color.GhostWhite;

                  }

                  ConnectionString.closeconnection();
              }
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
              ConnectionString.closeconnection();
          }

    }
Posted
Updated 18-Jul-18 15:34pm
Comments
OriginalGriff 18-Jul-18 8:34am
   
And?
What does that do that you didn't expect, or not do that you did?
Where are you stuck?
What help do you need?
Ali Khan 19-Jul-18 2:28am
   
thanks problem solved
Mike V Baker 18-Jul-18 11:07am
   
I see here code to fill the table from a data source. I can't see the SQL for the "individual_attendance" SP. Is there a LEFT OUTER JOIN in there so that the students will come in but there will be NULL for 'Attendance_id' if they haven't checked in? In that case the P/A will be Attendance_id == null ? "Absent" : "Present"
Ali Khan 19-Jul-18 2:28am
   
thanks problem solved

1 solution

"Derived" data is not generally stored in a database; it is calculated at run time only; create a "calculated" column using an expression:

DataColumn.Expression Property (System.Data)[^]
   
Comments
Ali Khan 19-Jul-18 2:28am
   
thanks problem solved

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900