private void LoadSchoolchildsInGpoup()
{
dataGridViewFastenSchoolchildsInGpoup.Rows.Clear();
DataGridViewComboBoxCell Cell;
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
queryString = "SELECT ID_Schoolchild, Family, Name, Patronymic, Birthday, EnrollmentDay FROM Schoolchilds WHERE ID_Group = '" + comboBoxFastenSchoolchildsInGroup.SelectedValue + "'";
SqlCommand command = new SqlCommand(queryString, connection);
SqlDataReader reader = command.ExecuteReader();
ushort i = 0;
try
{
while (reader.Read())
{
String[] row = { reader[0].ToString(), reader[0].ToString(), reader[1].ToString(), reader[2].ToString(), reader[3].ToString(), reader[4].ToString(), reader[5].ToString() };
dataGridViewFastenSchoolchildsInGpoup.Rows.Add(row);
Cell = (DataGridViewComboBoxCell)dataGridViewFastenSchoolchildsInGpoup.Rows[i++].Cells[1];
Cell.Value = reader[0];
}
}
finally
{
reader.Close();
}
connection.Close();
}
}
private void comboBoxFastenSchoolchidsInGroup_SelectedValueChanged(object sender, EventArgs e)
{
LoadSchoolchildsInGpoup();
}
ComboBox.SelectedValueChanged + SQLConnection
Код:
При данном коде в момент компиляции на строку
Код:
connection.Open();
Код:
LoadSchoolchildsInGpoup();