I am trying to create a search page, this allows the admin to search through the entries in the database by certain criteria, such as province (like state but diff country)
Here is the code I have so far. The problem is that I am not getting any errors. But I am also not getting any results. The page just posts back and returns to the blank search page. The GridView does not display any results.
here is my code as it stands:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Configuration
Partial Class administration_Search
Inherits System.Web.UI.Page
Protected Sub ProvinceButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ProvinceButton.Click
'get the search string from text box
Dim Search As String
Search = ("%" & ProvinceButton.Text & "%")
'if the string has value then continue with search
If Len(Trim(Search)) > 0 Then
Dim con As String = WebConfigurationManager.ConnectionStrings("fubar").ToString()
'build sql string
Dim s As String
s = ("SELECT id, surname, name FROM orders WHERE province like @strSearch")
'declar connection
Dim c As SqlConnection = New SqlConnection(con)
'add command
Dim x As New SqlCommand(s, c)
'add parameter
x.Parameters.AddWithValue("@strSearch", strSearch)
c.Open()
Dim r As SqlDataReader = x.ExecuteReader
GV.DataSource = r
GV.DataBind()
c.Close()
Else
Province.Text = ("Please enter search terms")
End If
End Sub
End Class
On the .aspx page I have a textbox (id: province) and a button (id:submit)
Can anyone spot where I am going wrong. Its very frustrating when you dont get errors or results :0)
Thanks!