by
29. settembre 2008 01.15
Ho ormai perso diverse ore per trovare un sistema per eseguire un "group by" o simili su un datatable questo perché ho estratto una query dal database con diverse righe doppie e non posso eseguire un raggruppamento direttamente sul database (ad esempio ho fatto delle union nello script SQL).
Attraverso questo codice riesco a creare un datatable raggruppando in un'unica riga le righe che hanno più righe su un campo A sommando i valori numerici B. dt è il datatable di partenza con ad esempio i dati ottenuti con una query sul database.
1: Dim dtAgg As DataTable = dt.Clone
2: dtAgg.PrimaryKey = New DataColumn() {dtAgg.Columns("A")}
3:
4: For I As Integer = 0 To dt.Rows.Count - 1
5: Dim dr As DataRow = dtAgg.Rows.Find(dt.Rows(I).Item("A"))
6: If IsNothing(dr) Then
7: dr = dtAgg.NewRow()
8: dr.Item("A") = dt.Rows(I).Item("A")
9: dr.Item("B") = dt.Rows(I).Item("B")
10: dtAgg.Rows.Add(dr)
11: Else
12: dr.Item("B") += dt.Rows(I).Item("B")
13: End If
14: Next
Ovviamente la personalizzazione del codice ti permetterà di risolvere problemi più complessi.
by
29. settembre 2008 00.07
Ciao a tutti. Come riuscire a cancellare da un datatable tutte le righe che sono uguali? Questa semplice funzione consente proprio di passare il datatable e restituirlo con le righe doppie eliminate.
1: Function EliminateDuplicates(ByVal dt As DataTable) As DataTable
2: Dim ssort As String = ""
3: Dim col As DataColumn
4: Dim scol As DataColumn
5: For Each scol In dt.Columns
6: If ssort <> "" Then ssort &= ","
7: ssort &= scol.ColumnName
8: Next
9:
10: dt.DefaultView.Sort = ssort
11: Dim i As Integer, bEquals As Boolean, c As Integer, ccount As Integer
12: ccount = dt.Columns.Count
13: For i = dt.Rows.Count - 1 To 1 Step -1
14: bEquals = True
15: For c = 0 To ccount - 1
16: If dt.DefaultView(i)(c).ToString() <> dt.DefaultView(i - 1)(c).ToString() Then
17: bEquals = False
18: Exit For
19: End If
20: Next c
21:
22: If bEquals Then
23: dt.DefaultView(i).Delete()
24: End If
25: Next
26:
27: Return dt
28: End Sub
by
28. settembre 2008 22.07
Ho girato tutta interet ma non ho trovato un semplice programmino che mi consente di trasformare uno script SQL in un banale codice VB.NET. Quindi ho deciso di realizzarlo e metterlo a disposizione di chiunque. Spero vi possa essere utile. Dopo aver inserito lo script SQL (o qualsiasi altro script) ed il nome della variabile, si può convertire in VB.NET.
Nella finestra sotto appare il codice e può essere copiato nella clipboard direttamente.
ConvertInCode.zip (9,80 kb)
by
23. settembre 2008 00.18
Ho trovato in giro per la rete diversi progetti OpenSource sviluppati in .NET sia in VB che in C#. L'elenco è interessante e quindi ve lo pubblico.
e-Commerce / Online Shopping Carts
- Dash Commerce - dashcommerce
- Dot Shopping Cart - dotshoppingcart
- VevoCart - vevocart
- e-Shop ASP.NET - e-shop
- PressTopia Shop - Presstopia
Content Management Systems
- Umbraco - Umbraco
- Rainbow Portal - Rainbow Portal
- DotNetNuke - Dotnetnuke
- The Beer House - TheBeerHouse
- My Web Pages Starter Kit - MyWebPagesStarterKit
- Basic CMS - basic-cms
- JMD CMS - JMDCMS
- Nickel & Dime CMS - ndcms
- Nolior EZNews - nolioreznews
Blogs / Blogging
- Blog Engine .NET - dotnetblogengine.net
- DasBlog - dasblog
- Sub Text - subtextproject
- PressTopia - presstopia
Link Directories
- (ASPLD) ASP.NET 3.5 Link Directory - n3o
- XD Link Directory - ex-designz
- ASP.NET 2.0 Link Directory - davemackey
Customer Relationship Management (CRM)
- Splendid CRM - splendidcrm
Wiki's
- FlexWiki - flexwiki
- ScrewTurn Wiki - screwturn
Forum / Portals / Networks
- Kigg (Digg like application) - Kigg
- Club Starter Kit - ClubStarterKit
- Mojoportal for Windows and Mono - Mojoportal
- Drop Things (Web 2.0 Portal) - Dropthings
- Yet Another Forum - Yetanotherforum
- DMG Forum - Dmgforums
Recruitment / Job Systems
- Job Site Starter Kit - binaryintellect
- Stock / Inventory Tracker - itracker
Web / E Mail
- DotNet Open Mail - dotnetopenmail
- qqMail - umailcampaign
- Sharp Web Mail - sharpwebmail
Image & Video Galleries
- Media Library Starter Kit - media-library
- ASP.NET Foto Gallery - pentabyte
- gPhotoNet - PhotoNet
Classifieds
- Classifieds Starter Kit - msdn
- Dating .NET - joemay
Misc
- ASP.NET Small Business Web Site Starter Kit - Starter kit
- ASP.NET Personal Site
- Time Tracking Website - Time tracking
- DinnerNow (Food Ordering System) - Dinner now
- Bug Tracker .NET - Bug tracker