I am trying to search a database using a user defined string from a text box. I am getting an error message with the "objectadaptor.Fill"
Here is the code:
Imports System.Data.OleDb
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Partial Class Search
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objConnection As OleDbConnection
Dim objCommand As OleDbCommand
Dim objAdapter As OleDbDataAdapter
Dim objDataSet As DataSet
Dim strSearch As String
Dim strSQLQuery As String
'some code taken from www.asp101.com
' Get Search
strSearch = TextBox1.Text
' If there's nothing to search for then don't search
' o/w build our SQL Query and execute it.
If Len(Trim(strSearch)) > 0 Then
' Set up our connection.
objConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" _
& "Data Source=" & Server.MapPath("DB\ScrumManagementSystem.accdb") & ";")
' Set up our SQL query text.
strSQLQuery = "SELECT FName AS Name, FROM tblUser " _
& "OR FName LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "ORDER BY FName;"
' Create new command object passing it our SQL query
' and telling it which connection to use.
objCommand = New OleDbCommand(strSQLQuery, objConnection)
' Get a DataSet to bind the DataGrid to
objAdapter = New OleDbDataAdapter(objCommand)
objDataSet = New DataSet()
objAdapter.Fill(objDataSet) 'problem line!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' DataBind DG to DS
dgPaging.DataSource = objDataSet
dgPaging.DataBind()
objConnection.Close()
Else
TextBox1.Text = "Enter Search Here"
End If
End Sub
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgPaging.SelectedIndexChanged
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Response.Redirect("myProjectsPage.aspx")
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
Please help!