<pre> private void btnClockIn_Click(object sender, EventArgs e)
{
//Grab the Current Date and Time & Setup Strings for Return Message
DateTime theDate;
theDate = DateTime.Now;
string strEmployee = cmbEmployee.GetItemText(cmbEmployee.SelectedItem);
string strJob = cmbJobCode.GetItemText(cmbJobCode.SelectedItem);
//Send the Current Date and Time to SQL Server
SqlConnection objConnect = new SqlConnection(sqlConnect);
string sqlClkin = "Insert Into tblTimeclock (tcEID, tcJID, tcClockIn) Values (@tcEID, @tcJID, @tcClockIn)";
objConnect.Open();
try
{
SqlCommand sqlClkIn = new SqlCommand(sqlClkin, objConnect);
sqlClkIn.Parameters.Add("@tcEID", strEmployee);
sqlClkIn.Parameters.Add("@tcJID", strJob);
sqlClkIn.Parameters.Add("@tcClockIn", theDate);
sqlClkIn.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
objConnect.Close();
}
//Display Message Box
MessageBox.Show("Hello, " + strEmployee.ToString() + ".\n" + "You are clocking in at: " + theDate.ToString() + "." + "\nYou will be working job " + strJob.ToString() + ".", "Clock In", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
}