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


LightSwitch è in beta 1

Microsoft ha rilasciato al momento in beta, il software denominato LightSwitch. Sarà un'edizioni di Visual Studio 2010 customizzata per LightSwich. Questo sistema consente di creare applicazioni facilmente e di grande effetto grafico. Si può creare direttamente nell'applicazione un database con dei campi nuovi tipo email o telefono.

 

Be the first to rate this post

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

Posted by enrico on Wednesday, August 25, 2010 4:59 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Esistenza di una tabella nel database

Ogni tanto c'è la necessità di sapere se sul database è presente una tabella oppure no. Con il seguente codice possiamo verificare facilmente se una tabella esiste. Il parametro da passare è comprensivo di schema, per esempio dbo.Anagrafiche.

In VB.NET:

Function TableExists(tableNameAndSchema As String) As Boolean
   Using connection As New SqlConnection(connectionString)
      Dim checkTable As String = [String].Format("IF OBJECT_ID('{0}', 'U') IS NOT NULL SELECT 'true' ELSE SELECT 'false'", tableNameAndSchema)
      Dim command As New SqlCommand(checkTable, connection)
      command.CommandType = CommandType.Text
      connection.Open()
 
      Return Convert.ToBoolean(command.ExecuteScalar())
   End Using
End Function

e anche in C#:

bool TableExists(string tableNameAndSchema){
   using (SqlConnection connection = new SqlConnection(connectionString))
   {     
     string checkTable = String.Format(
                         "IF OBJECT_ID('{0}', 'U') IS NOT NULL SELECT 'true' ELSE SELECT 'false'", tableNameAndSchema);
       SqlCommand command = new SqlCommand(checkTable, connection);
      command.CommandType = CommandType.Text;
      connection.Open();
 
      return Convert.ToBoolean(command.ExecuteScalar());   
   }
}

Ciao e buon lavoro!

Be the first to rate this post

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

Posted by enrico on Thursday, July 01, 2010 3:43 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Group by multipli e alias ai campi

Titolo quanto meno complesso. Partiamo da un esempio per spiegarmi meglio:

query = From a In eDao.MagazzinoArticoli Join m In eDao.MagazzinoMovimenti On a.IDArticolo Equals m.Articolo _
        Where m.Data <= tmp _
        Group By a.IDArticolo, a.CodArticolo, a.Descrizione, a.Fornitore, a.FornitoreCodice, a.PrezzoNetto1, a.UnitaMisura _
        Into car = Sum(m.QtaCaricata), scar = Sum(m.QtaScaricata), ret = Sum(m.QtaRettificata), imp = Sum(m.QtaImpegnata) _
        Select IDArticolo, CodArticolo, Descrizione, Fornitore, FornitoreCodice, QtaCaricata = car, QtaScaricata = scar, QtaRettificata = ret, _
               QtaImpegnato = imp, PrezzoNetto1, UnitaMisura

Esistono due tabella denominate MagazzinoArticoli (dove è presente la definizione degli articoli di un magazzino) e la tabella MagazzinoMovimenti (che raccoglie per ogni articoli i movimenti di carico e scarico). C'è il join tra le due tabelle e la condizione where sulla data del movimento. Il group by deve essere definito su tutti i campi su cui si esegue il raggruppamento. Dopo il comando Into si definisce una variabile alla quale dare il valore di un'oeprazione che nell'esempio è sempre un Sum.

Quando sono al select e devo specificare i campi, posso creare degli alias come se definissi una variabile. Attenzione: non è possibile riferirsi ai valori a ed m che identificano le due rispettive tabelle.

Ciao a presto!

 

Be the first to rate this post

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

Posted by enrico on Monday, May 31, 2010 7:35 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Linq e uno o più Left Outer Join

Avendo perso anche tutto il pomeriggio della giornata di oggi a capire come fare in Linq un banale Left Outer Join, vi posto la query in Linq che ho realizzato.

qry = From f In eDoc.Fatture Where f.Data <= tmp Group Join pn In eDoc.PrimaNota On f.IDFattura Equals pn.FatturaID Into fv = _
      Group From p In fv.DefaultIfEmpty Join a In eDoc.Anagrafiche On f.Anagrafica Equals a.IDAnagrafica _
      Where f.Data <= tmp And (p.Data >= tmp Or p.Data Is Nothing) And (f.Annullata Is Nothing Or f.Annullata >= tmp) _
      Select a.IDAnagrafica, f.IDFattura, f.Numero, f.TipoDocumento, a.RagSoc, a.Nome, f.Data, f.Scadenza, f.TotaleImponibile, _
      f.TotaleDocumento, f.TotaleIVA, f.Anticipata, f.AnticipataImporto, f.AnticipataBanca, f.AnticipataData, f.AnticipataPercentuale, f.Riscossa, f.Annullata


Spero che vi sia utile!

Be the first to rate this post

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

Categories: management | vb.net
Posted by enrico on Friday, May 21, 2010 8:55 PM
Permalink | Comments (0) | Post RSSRSS comment feed

IIS 7 e MSCaptcha

Vorresti utilizzare su IIS7 il componente MSCaptcha ma nonostante tutti le configurazione questo non funziona. Per configurare correttamente e farlo funzionare, nella sesione system.weserver\handlers inserire le seguenti righe di codice:

<add name="MSCaptchaImage"

path="CaptchaImage.axd"

verb="GET"

type="MSCaptcha.CaptchaImageHandler, MSCaptcha"

preCondition="integratedMode,runtimeVersionv2.0" />

In allegato il controllo

Bin.zip (16,72 kb)

Be the first to rate this post

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

Tags: ,
Categories: iis | windowsform
Posted by enrico on Wednesday, May 05, 2010 8:43 PM
Permalink | Comments (0) | Post RSSRSS comment feed

VB.NET App.Path

Ogni tanto a me servirebbe la funzione che esisteva nel vecchio VB6 di AppPath. L'ho banalmente ricreata anche in VB.NET

Private Function AppPath() as String
        return System.Windows.Forms.Application.StartupPath
End function

Be the first to rate this post

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

Categories: vb.net
Posted by enrico on Monday, May 03, 2010 2:11 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Impossibile aggiornare EntitySet...

Lavorando con le entità può succedere che si incontri il seguente problema (Bugs è una tabella):

System.Data.UpdateException: Impossibile aggiornare EntitySet 'Bugs' perché include DefiningQuery e nell'elemento <ModificationFunctionMapping> non esiste alcun elemento <InsertFunction> che supporti l'operazione corrente.

Tale problema si verifica se si usa il mapping da database e la tabella non ha definito una chiave primaria.

Be the first to rate this post

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

Posted by enrico on Tuesday, February 16, 2010 10:49 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Microsoft Report: aggiungere il numero di riga ad una tabella

Quando si crea una tabella con dei dati in Microsoft Report è tutto abbastanza facile. Un problema che non sapevo come risolvere era quello di inserire un numero di riga progressivo. Non ho trovato molte indicazioni su come fare ma poi ho sparato un'idea e ha funzionato.Il comando da eseguire nella cella dove visualizzare i numeri progressivi è la seguente:

=RowNumber(Nothing)

Facile, no? Ciao e buon lavoro a tutti!

Be the first to rate this post

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

Posted by enrico on Friday, January 22, 2010 5:48 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Accedere ad un file di risorsa globale in ASP.NET

Buon anno! Questo veloce tips per darvi il codice per accedere ad un elemento di una risorsa ovvero un file .resx che si trova all'interno della cartella App_GlobalResources. Ammettendo di aver creato il file Messages.resx ed aver inserito un elemento con nome Saluto, il codice da scrivere è il seguente:

Me.GetGlobalResourceObject("Messages", "Saluto").ToString

È necessario importare System.Globalization.

Be the first to rate this post

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

Tags: ,
Posted by enrico on Tuesday, January 05, 2010 11:51 AM
Permalink | Comments (0) | Post RSSRSS comment feed

contextSwitchDeadlock MDA

Questo errore fortunatamente compare solamente durante il debug di un'applicazione: semplicemente avverte che l'operazione che si sta effettuato sta impiegando molto tempo e risorse. Se però si clicca comunque su "Play" l'applicazione continua a proseguire normalmente la sua attività.

Diversi sono i link interessanti a proposito che vi segnalo:

L'ultimo link è forse quello più completo. Buon lavoro!

 

Be the first to rate this post

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

Posted by enrico on Friday, November 06, 2009 6:27 PM
Permalink | Comments (0) | Post RSSRSS comment feed