Sub btnSelect_Click(sender as Object,e as EventArgs)

'Store query into the variable
Dim SQL as String = "select * from products where pid=" & ProdID.text

'Create an Instance of the SqlConnection Class
Dim CON as New SqlConnection ("server=webserve;database=student;uid=student;pwd=icc;")

'Create an Instance of the SqlDataAdapter Class  
Dim SDA As New SqlDataAdapter(SQL,Con)
'Create an instance of DataTable to store query results
Dim DT As New DataTable(“Product”)

‘Execute query and fill datatable with results
'Check if the data table has any rows
If DT.Rows.Count > 0 Then

          message.text = ""
          'Bind data to textboxes. Use Rows(0) because we want to extract the first table row
          ProdName.text = DT.Rows(0).Item(“Pname”)
          ProdCat.text = DT.Rows(0).Item(“Pcat”)
          ProdPrice.text = DT.Rows(0).Item(“Pprice”)
          ProdDesc.text = DT.Rows(0).Item(“Pdesc”)

          'If record was not found, display a message
          message.text = "Sorry, the ID entered was not found in the database"
End If

End Sub


In the HTML page body you create the textboxes using the following IDs:

  • ProdName
  • ProdCat
  • ProdPrice
  • ProdDesc