I need the details of the student to get displayed when they click on detail button. Right now just the design is getting displayed but the student's details is not appearing. The student logins using regno. Here is the code for detail.aspx.cs page:
SqlConnection cn = new SqlConnection("Data Source=DESKTOP-UIGAOQI\\SQLEXPRESS;Initial Catalog=mydb;Integrated Security=True;");
protected void Page_Load(object sender, EventArgs e)
{
string i, s;
i = System.Convert.ToString(Application["uid"]);
cn.Open();
s = "select * from student where RegNo='" + i + "'";
SqlCommand cmd1 = new SqlCommand(s, cn);
SqlDataReader rs = cmd1.ExecuteReader();
while (rs.Read())
{
if (rs.GetString(6) == i)
{
//regno.Text = rs.GetString(6);
name.Text = rs.GetString(0);
std.Text = rs.GetString(1);
mob.Text = rs.GetString(2);
add.Text = rs.GetString(5);
dob.Text = rs.GetString(3);
gen.Text = rs.GetString(4);
}
}
cn.Close();
}
After logging in, the main page that contains links to detail,attandance and marks page would be displayed. When the display button is clicked, it redirects to the detail.aspx page which is designed as:
What do i change to display the student's details?
Mithilesh TataPosted Mar 29, 2024, 5:13 AM
It seems like there might be an issue with how you're retrieving the
RegNoin your SQL query.Here's what you should do:
Check the value of
Application["uid"]to ensure it contains the correct registration number of the student. You can print it or debug to verify its value.Ensure that the column index you're using in
GetStringcorresponds to the correct column in yourSELECTstatement.Since you're already filtering the result based on
RegNo, you don't need theifcondition inside thewhileloop. You can directly assign the values to your text boxes.Here's the modified
Page_Loadmethod:In this code:
ifcondition inside thewhileloop since you're already filtering based onRegNo.GetStringindices accordingly. Adjust them if your columns are in a different order.SumathiPosted Apr 3, 2024, 3:27 PM
Thank you, I got it now.