2
Answers

Type Conversion issue

Hi
Please sorry to post this again. Am still finding problem inserting a label displayed time into the database.
Am having this error with “ChkBoxLate = “LblTimeNow.Text””, that “cannot explicitly convert time string.

protected void BtnSubmit_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
          DateTime LblTimeNow = Convert.ToDateTime(LblTimeNow.ToString().Trim());
   CheckBox ChkBoxLate = (CheckBox)row.FindControl("ChkBoxLate");
                if (ChkBoxLate.Checked)
                {
                    ChkBoxLate = "LblTimeNow.Text";
                }
                else
                {
                    ChkBoxLate = string.Empty;
                }
            }
InsertAttendance(Late);

private void InsertAttendance(int regNo, string firstName, string lastName, string boxDay, DateTime boxDate, string hours, string status, string authorized)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
        {
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandText = "INSERT INTO AttendanceTable VALUES (@Late)";
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("@Late", late);
  conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
            }
        }

 

Answers (2)