vbdotnet.it

Tricks & tips, workaround, forum and ideas with .Net

About the author

Enrico Rossini è il gestore di questo blog.
E-mail me Send mail

Recent posts

Recent comments

Contributi

Best 6 ~ 6 users ~ 6 comments

Info legali

Le opinioni espresse in questo blog sono strettamente personali e ogni persona è responsabile dei commenti che inserisce. I marchi citati sono delle rispettive aziende.

© Copyright 2010

Advertising


Eseguire un "group by" su un datatable con sommatoria

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.

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Monday, September 29, 2008 2:15 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Eliminare le righe duplicate da un DataTable

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 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Monday, September 29, 2008 1:07 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Convert Script in Code

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)

 

Currently rated 3.5 by 2 people

  • Currently 3.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: vb.net | windowsform
Posted by enrico on Sunday, September 28, 2008 11:07 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Progetti OpenSource in .NET

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
  1. Dash Commerce - dashcommerce
  2. Dot Shopping Cart - dotshoppingcart
  3. VevoCart - vevocart
  4. e-Shop ASP.NET - e-shop
  5. PressTopia Shop - Presstopia
Content Management Systems
  1. Umbraco - Umbraco
  2. Rainbow Portal - Rainbow Portal
  3. DotNetNuke - Dotnetnuke
  4. The Beer House - TheBeerHouse
  5. My Web Pages Starter Kit - MyWebPagesStarterKit 
  6. Basic CMS - basic-cms
  7. JMD CMS - JMDCMS
  8. Nickel & Dime CMS - ndcms
  9. Nolior EZNews - nolioreznews
Blogs / Blogging
  1. Blog Engine .NET - dotnetblogengine.net
  2. DasBlog - dasblog
  3. Sub Text - subtextproject
  4. PressTopia - presstopia 
Link Directories
  1. (ASPLD) ASP.NET 3.5 Link Directory - n3o
  2. XD Link Directory - ex-designz
  3. ASP.NET 2.0 Link Directory - davemackey
Customer Relationship Management (CRM)
  1. Splendid CRM - splendidcrm
Wiki's
  1. FlexWiki - flexwiki
  2. ScrewTurn Wiki - screwturn 
Forum / Portals / Networks
  1. Kigg (Digg like application) - Kigg
  2. Club Starter Kit - ClubStarterKit
  3. Mojoportal for Windows and Mono - Mojoportal
  4. Drop Things (Web 2.0 Portal) - Dropthings
  5. Yet Another Forum - Yetanotherforum
  6. DMG Forum - Dmgforums
Recruitment / Job Systems
  1. Job Site Starter Kit - binaryintellect
  2. Stock / Inventory Tracker - itracker
Web / E Mail
  1. DotNet Open Mail - dotnetopenmail
  2. qqMail - umailcampaign
  3. Sharp Web Mail - sharpwebmail
Image & Video Galleries
  1. Media Library Starter Kit - media-library
  2. ASP.NET Foto Gallery - pentabyte
  3. gPhotoNet - PhotoNet
Classifieds
  1. Classifieds Starter Kit - msdn
  2. Dating .NET - joemay
Misc
  1. ASP.NET Small Business Web Site Starter Kit - Starter kit
  2. ASP.NET Personal Site
  3. Time Tracking Website - Time tracking
  4. DinnerNow (Food Ordering System) - Dinner now
  5. Bug Tracker .NET - Bug tracker

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: asp.net | vb.net | c#
Posted by enrico on Tuesday, September 23, 2008 1:18 AM
Permalink | Comments (0) | Post RSSRSS comment feed