Imports System.Data.SqlClient
Imports System.Web.Configuration

Partial Class postrequest
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim connection As SqlConnection
        Dim command As SqlCommand
        Dim reader As SqlDataReader
        Dim studentId As Integer = 0

        ' Set the content type
        Response.ContentType = "text/plain"
        Response.ContentEncoding = Encoding.UTF8

        If Request.Form("studentid") <> "" Then
            studentId = Request.Form("studentid")

            Try
                connection = New SqlConnection(WebConfigurationManager.ConnectionStrings("StudentConnectionString").ConnectionString)
                command = New SqlCommand("SELECT * FROM StudentTable WHERE StudentId=@Id", connection)
                command.Parameters.AddWithValue("@Id", studentId)

                Using connection
                    connection.Open()
                    reader = command.ExecuteReader()

                    If reader.HasRows Then
                        reader.Read()
                        Response.Write(CType(reader("Name"), String) & "<br/>")
                        Response.Write(CType(reader("Age"), Integer) & "<br/>")
                        Response.Write(CType(reader("Course"), String) & "<br/>")
                    Else
                        Response.Write("No matching row found")
                    End If

                    connection.Close()
                End Using
            Catch
                Response.Write("An error occurred")
            End Try

        Else
            Response.Write("No ID provided for search")
        End If

    End Sub

End Class
