Click here to Skip to main content
15,904,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to display the data retrieve from database to a table.


After i displayed to table as shown below, how do i enroll the student when clicked on "Enroll" based on the student id?

What I have tried:

public string getStudentData()
       {
           string data = "";
           using(SqlConnection conn = new SqlConnection(connectionString))
           {
               using(SqlCommand cmd = new SqlCommand())
               {
                   cmd.Connection = conn;
                   cmd.CommandType = CommandType.StoredProcedure;
                   cmd.CommandText = "UspGetStudents";
                   cmd.Connection.Open();
                   using(SqlDataReader sqlRdr = cmd.ExecuteReader())
                   {
                       // table = new DataTable();
                       // table.Load(reader);
                       if (sqlRdr.HasRows)
                       {
                           while (sqlRdr.Read())
                           {
                               int studentId = sqlRdr.GetInt32(0);
                               string Name = sqlRdr.GetString(1);
                               string EmailAddress = sqlRdr.GetString(2);
                               string Gender = sqlRdr.GetString(3);
                               data += "<tr><td>" + studentId + "</td>
                                            <td>" + Name + "</td>
                                            <td>" + EmailAddress + "</td>
                                            <td>" + Gender + "</td>
                                            <td><a href="#">"+Enroll+"</a></td></tr>";
                           }
                       }
                   }
               }
               return data;
           }
   }
Posted
Updated 9-Mar-17 16:13pm
Comments
Karthik_Mahalingam 9-Mar-17 22:12pm    
Not clear with the issue and the code you have posted

1 solution

HTML
<a href="#">"+Enroll+"</a>
Your anchor reference points to nothing. Point it to a page to accept an associated QueryString[^]

Or if this is an Asp.Net website, you would be much better off using the DataGrid Class (System.Web.UI.WebControls)[^]

Example of DataGrid in ASP.NET[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900