p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Basics (http://p2p.wrox.com/forumdisplay.php?f=60)
-   -   Listing and limiting items from a database (http://p2p.wrox.com/showthread.php?t=16203)

RPG SEARCH July 30th, 2004 01:23 PM

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?


planoie July 30th, 2004 09:46 PM

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.

mehdi62b July 31st, 2004 04:15 AM

Also you can use DataView(it's RowFilter property).
DataView dvw=new DataView(yourDataTable);


RPG SEARCH July 31st, 2004 01:09 PM

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


RPG SEARCH August 1st, 2004 12:00 PM

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?


bmains August 1st, 2004 12:25 PM

Use the Memo data type.


RPG SEARCH August 1st, 2004 02:10 PM

Execellent - thank you! [=)]


RPG SEARCH August 2nd, 2004 02:19 PM

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)

            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


        End Sub



RPG SEARCH August 3rd, 2004 04:00 AM

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


bmains August 3rd, 2004 06:57 AM

Change your insert to:

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


All times are GMT -4. The time now is 07:57 PM.

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