-2

pls help me i am stuck in the project and very hard in here. when i click on the one checkbox in the row which i have set the TrueValue=P in grid view property it store successfuly.but the FalseValue store as null on database. i want to store the 1 instead of the null or 0 so how can i do. it false value i have set in grid view property it didnt work.here is the image of my grid view. enter image description here here is my coding after the image of the grid view which store datafrom grid view into datbase. enter image description here

here is image of the database store value which i want to store the zero instead of the empty or null in cell. enter image description here

i just want to get the False value of the checkbox should store in database. thanks. my code for storing the value of the checkbox in the project.

{
      foreach (DataGridViewRow iteam in dtgAttandance.Rows)
      { 
           con.Open();
           SqlCommand cmd = new SqlCommand("INSERT INTO EmpAttandanceDetail Values('"
                +txtAttandID.Text+"','"
                + iteam.Cells[0].Value + "','"
                + iteam.Cells[1].Value + "','"
                + iteam.Cells[2].Value + "','"
                + iteam.Cells[3].Value + "','"
                + iteam.Cells[4].Value + "','"
                + iteam.Cells[5].Value + "','"
                + iteam.Cells[6].Value+ "','"
                + iteam.Cells[7].Value+ "','"
                + iteam.Cells[8].Value+ "')",con);

            cmd.ExecuteNonQuery();
            con.Close();
       }

       con.Open();
       SqlCommand cmdDetail = new SqlCommand("INSERT INTO EmpAttandance values('" + txtAttandID.Text + "','" + dtAttand.Text + "')", con);
       cmdDetail.ExecuteNonQuery();
       MessageBox.Show("Attandance Save Successfully");
       con.Close();
       AttandanceDateVerifier();
}
Stefan
  • 17,448
  • 11
  • 60
  • 79
  • 1
    Oh, and, you have a pretty big security issue in your query builder See: https://stackoverflow.com/questions/332365/how-does-the-sql-injection-from-the-bobby-tables-xkcd-comic-work ... and for the solution use this: https://learn.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlparameter?view=netframework-4.7.2 – Stefan Mar 03 '19 at 10:03
  • 1
    okay i putting my code – Ibrar Ahmad Mar 03 '19 at 10:15

1 Answers1

0

As a quick fix, you can invert cell 7's value: + !((bool)iteam.Cells[7].Value) + "','" might help, but I urge you to check the Parameterizing the SqlCommand links. It will force you to think about data types and will make your problem easier.

Stefan
  • 17,448
  • 11
  • 60
  • 79