Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
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 July 30th, 2004, 01:23 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default Listing and limiting items from a database

Hi there,

I want to pull "featured items" from a database but only want to limit the amount of items to 10. But i want the number to be able to be altered at any stage. What is the best way to do this? Would it be a data grid?

Cheers
Dave

__________________
David Jenkins
 
Old July 30th, 2004, 09:46 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

How you display it is up to you (datagrid, datalist, repeater, listbox, dropdownlist, etc). Restricting the list is up to the data source. You can do this in a couple ways:
1) If your database has the capability, you can have it only return the first X rows. In MSSQL this is done with "TOP X" as in "SELECT TOP 10 * FROM...".
2) Get the complete list, then reduce it only the first X. If you get back a datatable (in a dataset), you could remove all the rows past the Xth row.
 
Old July 31st, 2004, 04:15 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Also you can use DataView(it's RowFilter property).
-------
DataView dvw=new DataView(yourDataTable);
dvw.RowFilter="ID<=10";
yourDtaGrid.DataSource=dvw;
yourDtaGrid.DataBind();
-------
HTH.

--------------------------------------------
Mehdi.
 
Old July 31st, 2004, 01:09 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

Cool thanks for you responses. I will have a play and see which best applies to me. Thanks again.

David.

 
Old August 1st, 2004, 12:00 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

Another database related question- so far all the fields i have used only have a low amount of characters. But for a description field I want to put more than 255 characters in but access limits it. How do i enable unlimited characters?
cheers

David

 
Old August 1st, 2004, 12:25 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Use the Memo data type.

Brian
 
Old August 1st, 2004, 02:10 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

Execellent - thank you! [=)]

David
 
Old August 2nd, 2004, 02:19 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

Hi there,

I worked out some of the problems with the database and cant get any furture than this.

Syntax error in INSERT INTO statement.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.

Source Error:


Line 18: dbCommand.Parameters.Add("@CategoryName", OleDbType.VarChar, 15).Value = txtCategoryName.Text
Line 19:
Line 20: dbCommand.ExecuteNonQuery()
Line 21: dbConnection.Close()
Line 22:

the page generates alright but as soon a i click it generates the above.

page code is, left out html for ease, cheers:

<%@ Page Language="VB" Debug="true" %>
<%@ Register TagPrefix="Include" TagName="Header" Src="includes/header.ascx" %>
<%@ Register TagPrefix="Include" TagName="Footer" Src="includes/footer.ascx" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

    ' This is the code that insert the category name when it is clicked.
    Sub BtnCategoryCreate_Click (sender as object, e as eventargs)

            Dim connectionString as string = "Provider=Microsoft.Jet.OLEDB.4.0; Ole Db Services=-4; Data Source=C:\Inetpub\wwwroot\web sites\database\database.mdb"
            Dim dbConnection As New OleDbConnection(connectionString)
                dbConnection.Open()

            Dim commandString as string = "INSERT INTO Categories (CategoryName)"

            Dim dbCommand as new OleDbCommand(commandString, dbConnection)

            dbCommand.Parameters.Add("@CategoryName", OleDbType.VarChar, 15).Value = txtCategoryName.Text

            dbCommand.ExecuteNonQuery()
            dbConnection.Close()

        End Sub

</script>



David
 
Old August 3rd, 2004, 04:00 AM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

I deleted the dbCommand.ExecuteNonQuery() the page just refreshes and nothing is inserted into the database - argh!



David
 
Old August 3rd, 2004, 06:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Change your insert to:

"INSERT INTO Categories (CategoryName) values (@CategoryName)"

Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help, trying to fill grid w/database items itsajourney ADO.NET 1 May 24th, 2005 10:57 PM
Problem listing database tables raphaelsenra Pro VB Databases 0 January 6th, 2005 11:38 AM
displaying items from a database?? Ashleek007 PHP Databases 3 April 27th, 2004 06:05 PM
Listing Category then Items harpua Classic ASP Professional 3 December 12th, 2003 11:47 AM
Filenames and directories listing into database. wenzation VB.NET 2002/2003 Basics 1 November 14th, 2003 09:34 AM





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