Wrox Programmer Forums
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 15th, 2006, 07:31 AM
Registered User
Join Date: May 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Bind datagrid to recordset

Hi is there a way to encorporate the following working code into the datagrid example? thank you....

If strSearch <> "" Then
    ' MapPath of virtual database file path to a physical path.
    ' If you want you could hard code a physical path here.
        strDBPath = Server.MapPath("Contacts.mdb")

        ' Create an ADO Connection to connect to the sample database using OLE DB.
        cnnSearch = Server.CreateObject("ADODB.Connection")

    ' This line is for the Access sample database:
        cnnSearch.Open("Provider=Microsoft.Jet.OLEDB.4.0;D ata Source=" & strDBPath & ";")

        ' Build our query based on the input.
        strSQL = "SELECT * " _
         & "FROM [tblEmployee] " _
         & "WHERE Name LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
         & "ORDER BY Name;"

        ' Execute our query using the connection object. It automatically
        ' creates and returns a recordset which we store in our variable.
        rstSearch = cnnSearch.Execute(strSQL)

        ' Display a table of the data in the recordset. We loop through the
        ' recordset displaying the fields from the table and using MoveNext
        ' to increment to the next record.

<table border="1">

    Do While Not rstSearch.EOF

        <td><%= rstSearch.Fields("Name").Value %> </td>




    ' Close our recordset and connection and dispose of the objects
        rstSearch = Nothing
        cnnSearch = Nothing
End If


<asp:GridView ID="GridView1" runat="server" CellPadding="2"
          ForeColor="#333333" GridLines="None" BorderStyle="None" CellSpacing="2" HorizontalAlign="Center" Width="850px">

            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" Wrap="False" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" Wrap="False" />
            <EditRowStyle BackColor="#999999" Wrap="False" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" HorizontalAlign="Center" Wrap="False" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" Wrap="False" />


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to bind Recordset to an Access Subform in VB? fcortes BOOK: Access 2003 VBA Programmer's Reference 1 March 1st, 2008 08:39 PM
bind recordset to field ibgreen SQL Language 0 October 24th, 2006 12:48 PM
How to bind data from a recordset to a combobox? wayne62682 Access VBA 6 April 2nd, 2006 08:45 PM
Bind image to the datagrid learner_7983 ADO.NET 3 November 1st, 2004 02:00 AM
How to bind text box to recordset fields? cici VB How-To 2 December 1st, 2003 02:10 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.