例:管理者がグリッド内のすべてのデータを表示できる場合。教員としてログインすると、グリッド内の自分のデータのみを表示でき、残りは非表示にする必要があります。SQLクエリを変更することにより、(プライマリ)に基づいてフィルタリングできますfacultyID
が、グリッド内の位置を表示している間は、whileループのために変更されます。解決策を提案してください
private void FillDisGrid()
{
int a1 = 0;
int colNo = 1;
if (conn.State == ConnectionState.Open) { conn.Close(); }
conn.Open();
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
cmd.Connection = conn;
cmd.CommandText = "select Subjectname,FacultyID from timetabletab where FacultyID='" + comboBox2.Text + "' and semester='" + comboBox3.Text + "' order by rno";
dr = cmd.ExecuteReader();
while (dr.Read())
{
if (colNo % 6 == 0) { colNo = 1; a1 = a1 + 2; }
dataGridView1.Rows[a1].Cells[colNo].Value = dr.GetValue(0).ToString();
dataGridView1.Rows[a1 + 1].Cells[colNo].Value = dr.GetValue(1).ToString();
colNo++;
}
}