Forward-Only Data Model
– Single Value
Variable(query) – SqlConnection – SqlCommand – Variable(result)
– Multiple Values
Variable(query) – SqlConnection – SqlCommand – SqlDataReader – WebControl
Sub btnSelect_Click(sender as Object,e as EventArgs)
'Store query into the variable
Dim SQL as String = "select * from products”
'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 SqlCommand Class
Dim CMD As New SqlCommand(SQL,Con)
'Open Connection
Con.Open()
'Create a SqlDataReader and run the query to retrieve results
Dim SDR as SqlDataReader = CMD.ExecuteReader()
'Check if the data reader has any rows
If SDR.HasRows Then
message.text = ""
'Bind data to datagrid/repeater/dropdownlist/listbox
Results.DataSource = SDR
Results.DataBind()
Else
'If record was not found, display a message
message.text = "Sorry no records where found in the database"
End If
‘Close Data Reader
SDR.Close()
'Close Connection
Con.Close()
End Sub
In the HTML page body you create a datagrid/repeater/dropdownlist/listbox using the following ID:
- Results