Solved

Limit text in asp:Label text=" " to just 100 characters

Posted on 2008-10-22
4
1,320 Views
Last Modified: 2012-05-05
I am finishing up the development of a web site in ASP.NET with VB.NET and MS SQL Server 2005 on MS Visual Web Developer.  I have a query which pulls the record for a specified product from the table, returning the description field (varchar(6000)).  On my web page, I want to display just the first 100 characters of the description, followed by an elipse (...).  I'm out of time on this project so would like some help, please.
Dim myConn2 As New SqlConnection(ConfigurationManager.ConnectionStrings("omahavaccineConnectionString").ToString)
        myCmd2.Connection = myConn2
        myCmd2.CommandType = CommandType.Text
        myCmd2.CommandText = "Select * from Product where sku='" & strSKU & "' "
        myConn2.Open()
        Dim myReader2 As SqlDataReader = myCmd2.ExecuteReader()
        Do While myReader2.Read
            lblshort_description = (TRIM(myReader2("description")),100) & " ..."
        Loop
        myConn2.Close()

Open in new window

0
Comment
Question by:OVC-it-guy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 7

Accepted Solution

by:
the_bachelor earned 500 total points
ID: 22779389
you could do this on the database level
SELECT *, CASE 
	WHEN LEN([Description]) <=100 THEN [Description]
	ELSE SUBSTRING([Description], 1,100) + '(...)'
END AS ShortDescription FROM Product where ...

Open in new window

0
 

Author Comment

by:OVC-it-guy
ID: 22779445
Ooh, I like that better than what I was thinking.  Why return all that extraneous text when I only need about 100 characters?!?  I'll give that a try!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question