Solved

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

Posted on 2008-10-22
4
1,290 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Code works but I need to redo it and assign values to Model 7 32
vb.net checkbox 7 41
Replace &lt; with < 14 54
Need a starter for ETL protocol? 4 33
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now