Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 March 18th, 2005, 06:29 AM
Authorized User
 
Join Date: Jan 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default Something's wrong with this code...

...but I don't know what it is. It's syntactically correct, passes all compiler tests and all that, but returns no results. It's supposed display all jobs in the jobs table mathcing the user's search. it just displays the header od the datagrid.

<%@ Page Language="C#" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

    void Page_Load()
    {
        if (Page.IsPostBack)
        {
            lblMessage.Text="Your search results...";
        }
        else
        {
            lblMessage.Text="";
        }
    }


    void Search_Click(object sender, EventArgs e)
    {
        string Title = txtTitle.Text;
        string Location = txtLocation.Text;
        string Type="Permanent";


        DataGrid2.DataSource=ListJobs(Title,Location,Type) ;
        DataGrid2.DataBind();
    }



        System.Data.DataSet ListJobs(string Title, string Location, string Type)
        {
            string connectionString = "server=\'(local)\'; trusted_connection=true; database=\'nkonye_test\'";
            //string connectionString = ConfigurationSettings.AppSettings("ConnectionStrin g");
            System.Data.IDbConnection dbConnection = new System.Data.SqlClient.SqlConnection(connectionStri ng);


            string queryString = "SELECT [Jobs].* FROM [Jobs]" +
                                 " WHERE [Jobs].[job_title] LIKE '%@Title%' " +
                                 " OR [Jobs].[location] LIKE '%@Location%' " +
                                 " OR [Jobs].[job_type] LIKE '%@Type%'" ;

            System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();
            dbCommand.CommandText = queryString;
            dbCommand.Connection = dbConnection;

            //Title
            SqlParameter Jtitle = new SqlParameter("@Title",SqlDbType.VarChar,250);
            Jtitle.Value=Title;
            dbCommand.Parameters.Add(Jtitle);
            //Location
            SqlParameter JLoc = new SqlParameter("@Location",SqlDbType.VarChar,50);
            JLoc.Value=Location;
            dbCommand.Parameters.Add(JLoc);
            //job type
            SqlParameter JType = new SqlParameter("@Type",SqlDbType.VarChar, 50);
            JType.Value = Type;
            dbCommand.Parameters.Add(JType);


           // Response.Write(Title);
           // Response.Write("<br />");
           // Response.Write(Location);
           // Response.Write("<br />");
           // Response.Write(Type);
           // Response.End();


            System.Data.IDbDataAdapter dataAdapter = new System.Data.SqlClient.SqlDataAdapter();
            dataAdapter.SelectCommand = dbCommand;
            System.Data.DataSet dataSet = new System.Data.DataSet();
            dataAdapter.Fill(dataSet);

            return dataSet;
        }

</script>
<html>
<head>
</head>
<body>
    <form action="search.aspx" method="post" runat="server">
        <table cellpadding="0" width="750" align="center" cellpsacing="0">
            <tbody>
                <tr>
                    <td align="middle" colspan="2">
                        <a href="list.aspx">List</a> | Search | <a href="index.aspx">Log out</a>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                </tr>
                <tr>
                    <td colspan="2">
                        <h2>Search jobs
                        </h2>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                </tr>
                <tr>
                    <td>
                        Job title:</td>
                    <td>
                        <asp:textbox id="txtTitle" runat="server" size="45px"></asp:textbox>
                    </td>
                </tr>
                <tr>
                    <td>
                        Location:</td>
                    <td>
                        <asp:textbox id="txtLocation" runat="server" size="20px"></asp:textbox>
                    </td>
                </tr>
                <tr>
                    <td>
                        Type:</td>
                    <td>
                        <asp:dropdownlist id="Location" runat="server">
                            <asp:listitem id="Permanent">Permanent</asp:listitem>
                            <asp:listitem id="Contract">Contract</asp:listitem>
                        </asp:dropdownlist>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:button id="Search" onclick="Search_Click" runat="server" Text="Search"></asp:button>
                        <asp:button id="clear" runat="server" Text="Clear"></asp:button>
                    </td>
                </tr>
            </tbody>
        </table>
        <br />

        <br />
        <h3><asp:Label runat="server" id="lblMessage"></asp:Label>
        </h3>
        <br />
        <asp:DataGrid id="DataGrid2" runat="server" Autogeneratecolumns="False" align="center" width="650px" ForeColor="Black" CellPadding="4" BackColor="White" BorderColor="#DEDFDE" BorderWidth="1px" GridLines="Vertical" BorderStyle="None">
            <FooterStyle backcolor="#CCCC99"></FooterStyle>
            <HeaderStyle font-bold="True" forecolor="White" backcolor="#6B696B"></HeaderStyle>
            <PagerStyle horizontalalign="Right" forecolor="Black" backcolor="#F7F7DE" mode="NumericPages"></PagerStyle>
            <SelectedItemStyle font-bold="True" forecolor="White" backcolor="#CE5D5A"></SelectedItemStyle>
            <AlternatingItemStyle backcolor="White"></AlternatingItemStyle>
            <ItemStyle backcolor="#F7F7DE"></ItemStyle>
            <Columns>
                <asp:BoundColumn DataField="job_id" HeaderText="ID" ReadOnly="True" />
                <asp:BoundColumn DataField="job_title" HeaderText="Title"></asp:BoundColumn>
                <asp:BoundColumn DataField="location" HeaderText="Location"></asp:BoundColumn>
                <asp:BoundColumn DataField="job_type" HeaderText="Job Type"></asp:BoundColumn>
                <asp:BoundColumn DataField="salary" HeaderText="Salary" DataFormatString="{0:c}"></asp:BoundColumn>
                <asp:BoundColumn DataField="job_type" HeaderText="Type"></asp:BoundColumn>
                 <asp:templatecolumn>
                    <itemtemplate>
                        <a href='edit_job.aspx?job_id=<%# DataBinder.Eval ( Container.DataItem, "job_id") %>' > Edit</a>
                    </itemtemplate>
                </asp:templatecolumn>
                <asp:templatecolumn>
                    <itemtemplate>
                        <a href='delete_job.aspx?job_id=<%# DataBinder.Eval ( Container.DataItem, "job_id") %>' > Delete</a>
                    </itemtemplate>
                </asp:templatecolumn>
            </Columns>
        </asp:DataGrid>
    </form>
</body>
</html>
 
Old March 18th, 2005, 11:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Try binding to a datatable within the dataset, or try setting the datamember property. The datamember property sets which table within the dataset to bind to.

Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
what's wrong with my code? DyerOppenheimer BOOK: Beginning Ajax with ASP.NET 0 January 7th, 2008 08:46 AM
What's wrong with this code? appleseed C++ Programming 2 November 25th, 2006 08:17 AM
What's wrong with this code? AlDugan XSLT 3 May 19th, 2006 12:06 PM
What is wrong with code? rtr1900 Classic ASP Databases 1 April 3rd, 2006 03:20 AM
what's wrong with this code? miguel.ossa ASP.NET 1.0 and 1.1 Basics 2 January 21st, 2004 11:33 AM





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