Results 1 to 1 of 1

Thread: How to print aditional columns in search output?

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Arrow How to print aditional columns in search output?

    How to print paymentno,pen_date,amount columns in the seach output in addition to
    playerno column? The code blow only outputs the playerno

    <%@ Page Language="VB" Debug="True" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <script language="VB" runat="server">

    Sub btnSearch_OnClick(sender as Object, e as EventArgs)
    Dim objConnection As SqlConnection
    Dim objCommand As SqlCommand
    Dim objAdapter As SqlDataAdapter
    Dim objDataSet As DataSet
    Dim strSearch As String
    Dim strSQLQuery As String

    ' Get Search
    strSearch = txtSearch.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 SqlConnection("Data Source=(local);" _
    & "Initial Catalog=teniss2;User Id=web;Password=web;" _
    & "Connect Timeout=15;Network Library=dbmssocn;")


    ' Set up our SQL query text.
    strSQLQuery = "SELECT playerno" _
    & "FROM players " _
    & "WHERE penalities LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
    & "ORDER BY playerno;"

    ' Create new command object passing it our SQL query
    ' and telling it which connection to use.
    objCommand = New SqlCommand(strSQLQuery, objConnection)

    ' Get a DataSet to bind the DataGrid to
    objAdapter = New SqlDataAdapter(objCommand)
    objDataSet = New DataSet()
    objAdapter.Fill(objDataSet)

    ' DataBind DG to DS
    dgPaging.DataSource = objDataSet
    dgPaging.DataBind()

    objConnection.Close()
    Else
    txtSearch.Text = "Enter Search Here"
    End If
    End Sub

    </script>
    <html>
    <head>
    <title>ASP.NET Database Search</title>
    </head>
    <body>

    <form runat="server">

    <p>Search our sample db by first or last name. (% returns all)</p>

    <asp:TextBox id="txtSearch" runat="server" />

    <asp:Button id="btnSearch" runat="server"
    Text = "Search"
    OnClick = "btnSearch_OnClick"
    />

    <p>[Try 'am' or 'er' for an example]</p>

    <!-- Plain vanilla DataGrid... format it as you like. -->
    <aspataGrid id="dgPaging" runat="server"
    HeaderStyle-Font-Bold="True"
    />

    </form>

    <hr />

    <p>
    Click <a href=".asp">here</a>
    to read about and download the source code.
    </p>

    </body>
    </html>
    Last edited by tony007; May 2nd, 2005 at 10:30 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width