من الأفضل وضع الكود بهذه الطريقة لتسهيل القراءة :
تم تصحيح الكود :
PHP كود :
private int FindIDST(int IDST)
{
int id;
SqlCommand comm = new SqlCommand("SELECT * FROM Students where ID=@ID", conn);
SqlParameter p1 = new SqlParameter("@ID", IDST);
comm.Parameters.Add(p1);
if (conn.State == ConnectionState.Open) { conn.Close(); }
conn.Open();
SqlDataReader rd = comm.ExecuteReader();
if (rd.Read())
{
txtStID.Text = rd["ID"].ToString();
txtStName.Text = rd["StudentName"].ToString();
txtStPhone.Text = rd["Phone"].ToString();
}
else
{
MessageBox.Show("name not found");
}
id =Convert.ToInt32(rd[0]);
return id;
}
تم تصحيح الكود :
PHP كود :
private int FindIDST(int IDST)
{
int id;
SqlCommand comm = new SqlCommand("SELECT * FROM Students where ID=@ID", conn);
SqlParameter p1 = new SqlParameter("@ID", IDST);
comm.Parameters.Add(p1);
if (conn.State == ConnectionState.Open) { conn.Close(); }
conn.Open();
SqlDataReader rd = comm.ExecuteReader();
while (rd.Read())
{
txtStID.Text = rd["ID"].ToString();
txtStName.Text = rd["StudentName"].ToString();
txtStPhone.Text = rd["Phone"].ToString();
}
else
{
MessageBox.Show("name not found");
}
id =Convert.ToInt32(rd[0]);
return id;
}

