hi can anyone help me . when the user enter the name in a textbox and click the search button, the output should be display in the datagrid... Help plz have to submit my project in 8 days
Hi there
First of all you need to connect your data base to your page
Public Function CreateOleDbConnection() As OleDbConnection
Dim myConnString As String = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("~/App_Data/Training_db.mdb")
Dim myConnection As New OleDbConnection(myConnString)
myConnection.Open()
Return myConnection
End Function
Second assign you database called values to you datagrid
Public Sub SearchCourse(ByVal CourseID As String)
Try
Dim sql As String = "SELECT CourseID, CourseName, Date_From,Date_To, SeatsAvailible FROM CourseInfo WHERE CourseName='" & coursename & "'"
Dim cmnd As New OleDbCommand(sql, CreateOleDbConnection)
Dim dataset As New DataSet()
Dim adapter As New OleDbDataAdapter(cmnd)
adapter.Fill(dataset)
adapter.Dispose()
'binding you datagrid with data from you database that which you have called
GridTrainingCourse.DataSource = dataset.Tables(0)
GridTrainingCourse.DataBind()
cmnd.Dispose()
CreateOleDbConnection.Close()
Catch ex As Exception
lblNoRecords.Text = "No records found, please redefine your search"
End Try
End Sub
Third call the function/sub to clicking event of you button.
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
'search value
Dim CourseID as string= txtSearch.Text
SearchCourse(CourseID)
End Sub