{"Cross-thread operation not valid: Control 'cmbLateTxt' accessed from a thread other than the thread it was created on."}
What I have tried:
public enum ClientLate
<pre lang="c#">
{
Sele
ct = 1,
Insert_Select = 2
}
public void lateTimeMethod(ClientLate C_late, ComboBox cmbLateTxt)
{
using (SqlConnection con = new SqlConnection(_con))
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Select_All_Lateness";
con.Open();
if (C_late == ClientLate.Select)
{
cmd.Parameters.AddWithValue("@status", C_late);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
cmbLateTxt.Items.Add(reader[0]);
}
}
else if (C_late == ClientLate.Insert_Select)
{
if (cmbLateTxt != null)
{
int id = int.Parse(cmbLateTxt.SelectedItem.ToString());
cmd.Parameters.AddWithValue("@status", C_late);
cmd.Parameters.AddWithValue("@reason",id);
SetPromptLateness("Reason Submitted Successfully");
int i = cmd.ExecuteNonQuery();
}