problem with search application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • preeti13
    New Member
    • Aug 2007
    • 67

    problem with search application

    hi friends please help me with my problem i have a code for search application it is searching one record from the data base at a time but i have so many records with that name but its not searching the whole list please help me how i can search the whole list of the same names
    my code is like this
    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Report.aspx.cs" Inherits="SearchReport.Report" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Report</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <table cellpadding="0" width="700" align="center" border="1">
        <tr>
        <td height="50"><img src="header.jpg" alt="header" width="700"/>
        </td>
        </tr>
        <tr>
        <td>
        Search:
        <asp:TextBox ID="txtreport" runat="server"></asp:TextBox>
         <asp:DataGrid ID="gridreport" runat="server" AutoGenerateColumns="false">
         <Columns>
         <asp:BoundColumn DataField="Name" HeaderText="Name" HeaderStyle-BackColor="Gray"></asp:BoundColumn>
         <asp:BoundColumn DataField="Path" HeaderText="Path" HeaderStyle-BackColor="gray"></asp:BoundColumn>
         <asp:BoundColumn DataField="Description" HeaderText="Description" HeaderStyle-BackColor="gray"></asp:BoundColumn>
         
         </Columns>
         
         </asp:DataGrid>
        </td>
        </tr>
        <tr>
        <td>
        <asp:Button ID="cmdbutton" align="center" Text="Search" runat="server" OnClick="cmdbutton_Click" />
        </td>
        </tr>
        </table>
        </div>
        </form>
    </body>
    </html>
    
    
    
    
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using System.Data.SqlTypes;
    
    namespace SearchReport
    {
        public partial class Report : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void txtreport_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            protected void cmdbutton_Click(object sender, EventArgs e)
            {
                SqlConnection oConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]);
                SqlDataAdapter da = new SqlDataAdapter("dbo.win_ReportListSearch", oConn);
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
    
                
                DataSet ds = new DataSet();
                
                   da.SelectCommand.Parameters.Add(new SqlParameter("@Name",txtreport.Text));
    
                  //if (txtreport.Text.ToString() != "")
                  //{
                   //da.SelectCommand.Parameters.Add(new SqlParameter("@Name", txtreport.Text));
                   //}
    
                oConn.Open();
                da.SelectCommand.ExecuteNonQuery();
                oConn.Close();
    
                da.Fill(ds);
    
                this.gridreport.DataSource = ds;
                this.DataBind();
    
                da.Dispose(); 
    
            }
        }
    }


    and the store procedure is like this

    Code:
    ALTER PROCEDURE [dbo].[win_ReportListSearch]
    @Name varchar(30)
    as
    
    
    SELECT [Name],
           [Path],
           [Description]
    FROM Catalog
    WHERE [Name] like (@name)
    
    
    please help me with this problem
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    Please try the following

    [CODE=sql]ALTER PROCEDURE [dbo].[win_ReportListS earch]
    @Name varchar(30)
    as


    SELECT [Name],
    [Path],
    [Description]
    FROM Catalog
    WHERE [Name] like ('%'+@name+'%')[/CODE]
    the % symbols are place holders allowing the name to be at any location in the text

    Your previous code was as good as "Where [Name] = @name"

    Comment

    • preeti13
      New Member
      • Aug 2007
      • 67

      #3
      thanks so much it worked for me thanks once again to helping me with this problem

      Comment

      Working...