0

Hai... I'm Doing my project in asp .net(vb .net coding)
If anybody guide me means it would be great pleasure for me...
I want to display names in the list box
So i used the coding:

If Not Page.IsPostBack Then
Try
myda = New SqlDataAdapter("Select name from agent", connection)
ds = New DataSet
myda.Fill(ds, "agent") ListBox2.DataSource = ds
ListBox2.DataTextField = ds.Tables(0).Columns("Lastname").ColumnName.ToString()
ListBox2.DataBind() 
Catch ex As Exception
End Try
End If

Now i want to display count value near the name ...
The below names will be displayed in the listbox when the page loads

For ex:

Thomus
Adson
Thomus
Al-hert
Aroson
Thomus

Here 3 thomus are there ,for this i have to set values like this

For ex:

Thomus,3
Adson,1
Al-hert,1

This should be displayed on the listbox can any one say what to do and how to do with little ex :-/:?: ...

Thanks in advance...

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Mohtshm
0

u should make use of sql by this

select (name + CAST( count (name) AS varchar(10)) ) as NameCount from agent group by name
and also remember to make change in binding expression for testfieldvalue

0

u should make use of sql by this

select (name + CAST( count (name) AS varchar(10)) ) as NameCount from agent group by name
and also remember to make change in binding expression for testfieldvalue

Problem Solved thanks for ur reply

0

Yes you can use this query select (name + ',' + convert(varchar(10),count(name))) as NameCount
from agent group by name

you can either use cast or convert function.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.