Click here to Skip to main content
15,905,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My CODE:
C#
private void btnSave_Click(object sender, EventArgs e)
       {
           //MessageBox.Show(grStudentAttend.Rows.Count.ToString());
           //int count = grStudentAttend.Rows.Count;
           try
           {
               for (int i = 0; i < grStudentAttend.Rows.Count -1; i++)
               {
                   db.command.Parameters.Add("@StudentName", SqlDbType.VarChar).Value =grStudentAttend.Rows[i].Cells[0].Value.ToString();
                   db.command.Parameters.Add("@Roll", SqlDbType.VarChar).Value = grStudentAttend.Rows[i].Cells[1].Value.ToString();
                   db.command.Parameters.Add("@Class", SqlDbType.VarChar).Value = comClass.Text.ToString();
                   db.command.Parameters.Add("@Shift", SqlDbType.VarChar).Value = cmShift.Text.ToString();
                   db.command.Parameters.Add("@Section", SqlDbType.VarChar).Value = cmSection.Text.ToString();
                   db.command.Parameters.Add("@Dated", SqlDbType.SmallDateTime).Value = Convert.ToDateTime(dateTimePicker1.Text.ToString());
                   db.command.Parameters.Add("@YearAt", SqlDbType.VarChar).Value = dateTimeYear.Text.ToString();
                   db.command.Parameters.Add("@MonthAt", SqlDbType.VarChar).Value = comMonth.Text.ToString();
                   if (DBNull.Value.Equals(grStudentAttend.Rows[i].Cells[2].Value) || grStudentAttend.Rows[i].Cells[2].Value.ToString() == "false")
                   {
                       db.command.Parameters.Add("@Attend", SqlDbType.Bit).Value = 0;
                       //db.Adapter("sp_InsertStudentAttendance", true);
                       //MessageBox.Show("Keep Attendance complete");

                   }
                   else
                       db.command.Parameters.Add("@Attend", SqlDbType.Bit).Value = 1;
                   db.Adapter("sp_InsertStudentAttendance", true);
                   MessageBox.Show("Keep Attendance complete");
               }
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
           }
       }


Problem: Only checkbox-cell of datagridview is checked than insert successfully but, otherwise its not inserted. I am trying to keeping true and false record from datagridview but, only true value is inserted. how can I insert both record?
Posted

1 solution

Remove
C#
if (DBNull.Value.Equals(grStudentAttend.Rows[i].Cells[2].Value) || grStudentAttend.Rows[i].Cells[2].Value.ToString() == "false")
condition from the code and also the comment only else. It will work.
 
Share this answer
 
v2
Comments
UL UL ALBAB 3-Jul-12 6:32am    
It doesn't working...

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



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