I am working on a project, its purpose is to search a database and display the results in a data list so they can be used. I have the search working correctly but it only outputs to a data grid. Help please!

Protected Sub Button2_OnClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim objCommand As OleDbCommand
        Dim objAdapter As OleDbDataAdapter
        Dim objDataSet As DataSet
        Dim strSearch As String

        Dim objConnection As String = ("Provider=Microsoft.ACE.OLEDB.12.0;" _
            & "Data Source=" & Server.MapPath("DB\ScrumManagementSystem.accdb") & ";")

        Dim cn As New OleDbConnection(objConnection)
        Dim strSQLQuery As String

        strSearch = TextBox1.Text

        If Len(Trim(strSearch)) > 0 Then

            strSQLQuery = "SELECT FName & SName FROM tblUser WHERE FName LIKE '%" & Replace(strSearch, "'", "''") & "%' ORDER BY FName;"

            cn.Open()
            Dim cmd As New OleDbCommand(strSQLQuery, cn)

            objCommand = New OleDbCommand(strSQLQuery, cn)

            objAdapter = New OleDbDataAdapter(objCommand)
            objDataSet = New DataSet()
            objAdapter.Fill(objDataSet)

            dgPaging1.DataSource = objDataSet
            dgPaging1.DataBind()

            cn.Close()
        Else
            TextBox1.Text = "Enter search criteria!"
        End If
    End Sub

Recommended Answers

All 2 Replies

You have to configure ItemTemplate and other templates of DataList . Take a look at tutorial - http://www.asp.net/Learn/data-access/tutorial-29-vb.aspx

Not sure what to make of that? When using DataList, is it not possible to use data bind like i would have done with a typical gridview? Also the data i am reaning in is coming from a database (2007) after a search criteria has been applied, so selecting a data source wont work. Help please

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.