Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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 September 6th, 2004, 06:30 PM
Authorized User
 
Join Date: Aug 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default search box

Hi -

I have a few problems....1st creating a search box - this is what i have so far:

<HTML>
<HEAD>
    <script language="vb" runat="server">

    Sub Page_Load(Sender As Object, E As EventArgs)

        Dim MyConnection As SqlConnection = New SqlConnection("server=(local);database=XXX;Trusted _Connection=yes")

        Dim MyCommand As SqlCommand = New SqlCommand("select location from location where location like'%' & TextBox1.Text & '%'", MyConnection)

        MyConnection.Open()
        Dim dr As SqlDataReader = MyCommand.ExecuteReader()
    End Sub

    </script>
    </HEAD>
    <body>
        <form runat="server">
        <asp:Label id="Label1" runat="server" Font-Names="Verdana" Font-Size="X-Small" Font-Bold="True"
                style="Z-INDEX: 100; LEFT: 16px; POSITION: absolute; TOP: 24px">Search Location</asp:Label>
            <asp:TextBox id="TextBox1" runat="server" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 48px"></asp:TextBox>
            <asp:Button id="Button1" runat="server" Text="Search" style="Z-INDEX: 102; LEFT: 184px; POSITION: absolute; TOP: 48px"></asp:Button>
        </form>
    </body>
</HTML>

The error messages state that the column prefix 'TextBox1' does not match with a table name or alilas name use in the query. From this i am guessing that i have referenced TextBox1 in the wrong place. Can someone guide me in the right direction here please??

Once I have this search box set up, i need the results of the search to be in a listbox (when submit selected). Any suggestions on how to go about doing this??

I then need to be able to select the chosen result and submit it so that it is pasted (on the same page) in a textbox.

Any suggestions??

rizp
 
Old September 6th, 2004, 06:48 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

That is because you have used Single quotes instead of Double quotes in there, so that TextBox1.Text has become a constant and LIKE expects the string to be formatted as '%something%', which in your case shows up as '%'TextBox1.Text'%' is not valid and when searched in the table, it results in error.

Try this.
Code:
Dim MyCommand As SqlCommand = New SqlCommand("select location from location where location like'%" & TextBox1.Text & "%'", MyConnection)
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old September 6th, 2004, 07:38 PM
Authorized User
 
Join Date: Aug 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

that seems to have solved the erro message, however, when i search, i cant see any results - why is this???

Any suggestions about the questions on the post?

rizp
 
Old September 7th, 2004, 06:59 AM
Authorized User
 
Join Date: Aug 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Please can anyone suggest a solution to the problems i have above??

thanks,
rizp

 
Old September 8th, 2004, 01:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

is ur Solution Config set to DEBUG?

Always:),
Hovik Melkomian.
 
Old September 10th, 2004, 04:49 PM
Authorized User
 
Join Date: Aug 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi
why, should it be set to debug??

rizp





Similar Threads
Thread Thread Starter Forum Replies Last Post
Search / List Box Question. sprocket Access 2 July 13th, 2006 01:28 PM
Create search box yami56 Access 0 August 5th, 2004 05:42 AM
Search Box acdsky Classic ASP Basics 1 July 5th, 2004 02:51 AM
Getting a search txt box to work JJ Access VBA 4 October 23rd, 2003 10:19 AM
Search using drop down list box and a text box tcasp Classic ASP Basics 1 July 31st, 2003 02:58 PM





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