Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

hi all, im a newbie vb .net

im using dataset instead of sql statements to make database connection and modifying data.

 

i have a table with a column call abc

i want 2 select all the data in that column and show in a combobox at a windows form but i juz want 2 show the data once if the column hav more than a records are same.

 

for sql statement is

select distinct (column name) from (table name)

 

how about in dataset?

 

pls help me thx in advance

Posted

thx so much im reading now and try to understand it. but can u post the code for me when u r working? coz i still fresh in dataset and i need more references.

 

the code show that we need 2 use algorithm 2 check the value 1 by 1 rite? so mean that it not like in sql statement juz use the select distinct?

 

one more question? wat is the advantages in dataset instead of sql statement to connect a database

Posted

Here's what you need from the article (I think):

 

Public Function SelectDistinct(ByVal TableName As String, _

ByVal SourceTable As DataTable, _

ByVal FieldName As String) As DataTable

Dim dt As New DataTable(TableName)

dt.Columns.Add(FieldName, SourceTable.Columns(FieldName).DataType)

Dim dr As DataRow, LastValue As Object

For Each dr In SourceTable.Select("", FieldName)

If LastValue Is Nothing OrElse Not ColumnEqual(LastValue, dr(FieldName)) Then

LastValue = dr(FieldName)

dt.Rows.Add(New Object() {LastValue})

End If

Next

If Not ds Is Nothing Then ds.Tables.Add(dt)

Return dt

End Function

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...