Refreshing a Gridview
I have the code below it searches a database using the SQL LIKE command and populates a gridview. The only problem is when I search once I cant search again unless I reload the page. Is there a way I can close and reopen the connection or refresh so that I can enter text to search again.
Imports System.Data
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
' create a connection string
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("runnersdb.mdb")
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = connString
' create a data adapter
'Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Runners", myConnection)
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Runners WHERE Name LIKE '%" & txtName.Text & "%'", myConnection)
' create a new dataset
Dim ds As DataSet = New DataSet
' fill dataset
'ds.Clear()
ds.Reset()
da.Fill(ds, "Runners")
' Attach DataSet to DataGrid
GridView1.DataSourceID() = ""
GridView1.DataSource = ds.Tables(0).DefaultView
'myConnection.Close()
End Sub
End Class
|