Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 30th, 2004, 01:23 PM
Friend of Wrox
 
Join Date: Apr 2004
Location: Preston, Lancashire, United Kingdom.
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
  #2 (permalink)  
Old July 30th, 2004, 09:46 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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.
  #3 (permalink)  
Old July 31st, 2004, 04:15 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
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.
  #4 (permalink)  
Old July 31st, 2004, 01:09 PM
Friend of Wrox
 
Join Date: Apr 2004
Location: Preston, Lancashire, United Kingdom.
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.

  #5 (permalink)  
Old August 1st, 2004, 12:00 PM
Friend of Wrox
 
Join Date: Apr 2004
Location: Preston, Lancashire, United Kingdom.
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

  #6 (permalink)  
Old August 1st, 2004, 12:25 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Use the Memo data type.

Brian
  #7 (permalink)  
Old August 1st, 2004, 02:10 PM
Friend of Wrox
 
Join Date: Apr 2004
Location: Preston, Lancashire, United Kingdom.
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

Execellent - thank you! [=)]

David
  #8 (permalink)  
Old August 2nd, 2004, 02:19 PM
Friend of Wrox
 
Join Date: Apr 2004
Location: Preston, Lancashire, United Kingdom.
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
  #9 (permalink)  
Old August 3rd, 2004, 04:00 AM
Friend of Wrox
 
Join Date: Apr 2004
Location: Preston, Lancashire, United Kingdom.
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
  #10 (permalink)  
Old August 3rd, 2004, 06:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Change your insert to:

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

Brian
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:27 PM.


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