나는 2 개의 함수를 가지고 있으므로, function1이 완료되면 함수 2가 실행되고 싶습니다. 그렇지 않으면 함수 2가 실행되지 않도록해야합니다. 실행 (Didnot Execute !!).fun1 완료되면 fun2, 그렇지 않으면 fun2 않습니다.
public void SaveDuplicatCourse()
{
if(con.State !=ConnectionState.Open)
con.Open();
List<int> IDs = new List<int>();
foreach (DataGridViewRow r in dataGridViewStudents.Rows)
{
if (r.Cells[0].Value != null && bool.Parse(r.Cells[0].Value.ToString()))
{
IDs.Add(int.Parse(r.Cells[1].Value.ToString()));
}
}
foreach (int i in IDs)
{
try
{
SqlCommand com = new SqlCommand(@"Insert into DuplicateCourses
values(" + i + "," + CCID + ")", con);
com.ExecuteNonQuery();
}
catch (Exception)
{
MessageBox.Show("They are exist");
}
}
con.Close();
}
public void Save()
{
SqlCommand com = new SqlCommand(@"Delete from students
where
Course_ID = " + ID, con);
con.Open();
com.ExecuteNonQuery();
List<int> IDs = new List<int>();
foreach (DataGridViewRow r in dataGridViewStudents.Rows)
{
if (r.Cells[0].Value!=null && bool.Parse(r.Cells[0].Value.ToString()))
{
IDs.Add(int.Parse(r.Cells[1].Value.ToString()));
}
}
foreach (int i in IDs)
{
com.CommandText = "Insert into students values(" + i + "," + ID + ")";
com.ExecuteNonQuery();
}
con.Close();
}
나는 그것이 방법을 가르쳐주세요
private void buttonSaveChanges_Click(object sender, EventArgs e)
{
SaveDuplicatCourse();
Save();
}
아래로 ButtonClick
에서이 함수를 호출 : 아래로 서로 코드,
내 기능 1 SaveDuplicatCourse()
에 전화 기능 2 Save()
라고 끝날거야.
나는 당신이 무슨 말을하는지 모른다. '실행되지 않았다 '?? 뭐야 ...? –
이러한 함수가 void 대신 bool을 반환하도록합니다. – MikeTheLiar
첫 번째 함수에서'bool'을 리턴합니까? –