yewmeng Posted December 25, 2003 Posted December 25, 2003 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 Quote
mocella Posted December 26, 2003 Posted December 26, 2003 Check out this MSDN article and tweak it to your needs: http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B325684 I've got a shortened version of this code I use, but I'm not at work, or I'd post if for you. Quote
yewmeng Posted December 26, 2003 Author Posted December 26, 2003 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 Quote
mocella Posted December 26, 2003 Posted December 26, 2003 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.