Connecting Tech Pros Worldwide Forums | Help | Site Map

problem with search application

Member
 
Join Date: Aug 2007
Posts: 67
#1: Dec 26 '07
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
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Report.aspx.cs" Inherits="SearchReport.Report" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >
  6. <head runat="server">
  7.     <title>Report</title>
  8. </head>
  9. <body>
  10.     <form id="form1" runat="server">
  11.     <div>
  12.     <table cellpadding="0" width="700" align="center" border="1">
  13.     <tr>
  14.     <td height="50"><img src="header.jpg" alt="header" width="700"/>
  15.     </td>
  16.     </tr>
  17.     <tr>
  18.     <td>
  19.     Search:
  20.     <asp:TextBox ID="txtreport" runat="server"></asp:TextBox>
  21.      <asp:DataGrid ID="gridreport" runat="server" AutoGenerateColumns="false">
  22.      <Columns>
  23.      <asp:BoundColumn DataField="Name" HeaderText="Name" HeaderStyle-BackColor="Gray"></asp:BoundColumn>
  24.      <asp:BoundColumn DataField="Path" HeaderText="Path" HeaderStyle-BackColor="gray"></asp:BoundColumn>
  25.      <asp:BoundColumn DataField="Description" HeaderText="Description" HeaderStyle-BackColor="gray"></asp:BoundColumn>
  26.  
  27.      </Columns>
  28.  
  29.      </asp:DataGrid>
  30.     </td>
  31.     </tr>
  32.     <tr>
  33.     <td>
  34.     <asp:Button ID="cmdbutton" align="center" Text="Search" runat="server" OnClick="cmdbutton_Click" />
  35.     </td>
  36.     </tr>
  37.     </table>
  38.     </div>
  39.     </form>
  40. </body>
  41. </html>
  42.  
  43.  
  44.  
  45.  
  46. using System;
  47. using System.Data;
  48. using System.Configuration;
  49. using System.Collections;
  50. using System.Web;
  51. using System.Web.Security;
  52. using System.Web.UI;
  53. using System.Web.UI.WebControls;
  54. using System.Web.UI.WebControls.WebParts;
  55. using System.Web.UI.HtmlControls;
  56. using System.Data.SqlClient;
  57. using System.Data.SqlTypes;
  58.  
  59. namespace SearchReport
  60. {
  61.     public partial class Report : System.Web.UI.Page
  62.     {
  63.         protected void Page_Load(object sender, EventArgs e)
  64.         {
  65.  
  66.         }
  67.  
  68.         protected void txtreport_TextChanged(object sender, EventArgs e)
  69.         {
  70.  
  71.         }
  72.  
  73.         protected void cmdbutton_Click(object sender, EventArgs e)
  74.         {
  75.             SqlConnection oConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]);
  76.             SqlDataAdapter da = new SqlDataAdapter("dbo.win_ReportListSearch", oConn);
  77.             da.SelectCommand.CommandType = CommandType.StoredProcedure;
  78.  
  79.  
  80.             DataSet ds = new DataSet();
  81.  
  82.                da.SelectCommand.Parameters.Add(new SqlParameter("@Name",txtreport.Text));
  83.  
  84.               //if (txtreport.Text.ToString() != "")
  85.               //{
  86.                //da.SelectCommand.Parameters.Add(new SqlParameter("@Name", txtreport.Text));
  87.                //}
  88.  
  89.             oConn.Open();
  90.             da.SelectCommand.ExecuteNonQuery();
  91.             oConn.Close();
  92.  
  93.             da.Fill(ds);
  94.  
  95.             this.gridreport.DataSource = ds;
  96.             this.DataBind();
  97.  
  98.             da.Dispose(); 
  99.  
  100.         }
  101.     }
  102. }
  103.  
  104.  
  105.  


and the store procedure is like this

Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE [dbo].[win_ReportListSearch]
  2. @Name varchar(30)
  3. as
  4.  
  5.  
  6. SELECT [Name],
  7.        [Path],
  8.        [Description]
  9. FROM Catalog
  10. WHERE [Name] like (@name)
  11.  
  12.  
  13. please help me with this problem
  14.  
  15.  

Shashi Sadasivan's Avatar
Moderator
 
Join Date: Aug 2007
Location: Brisbane, Australia
Posts: 1,414
#2: Dec 27 '07

re: problem with search application


Please try the following

Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE [dbo].[win_ReportListSearch]
  2. @Name varchar(30)
  3. as
  4.  
  5.  
  6. SELECT [Name],
  7.        [Path],
  8.        [Description]
  9. FROM Catalog
  10. WHERE [Name] like ('%'+@name+'%')
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"
Member
 
Join Date: Aug 2007
Posts: 67
#3: Dec 27 '07

re: problem with search application


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