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 una script SQL (Run a script SQL)

A me capita spesso di dover eseguire degli script anche complessi su dei database come ad esempio gli script di aspnet. Ecco quindi un po' di codice per risolvere, come sempre brillantemente :), il problema!

   1:  #Region " Codice per l'esecuzione di script SQL "
   2:   
   3:      Private Function GetScriptStatements(ByVal p As String) As String()
   4:          Dim statements As String() = p.Split(New String() {"GO " & vbCr & vbLf}, StringSplitOptions.RemoveEmptyEntries)
   5:          Return statements
   6:      End Function
   7:   
   8:      Private Sub ExecuteStatements(ByVal statements As String(), ByVal connectionString As String)
   9:          If statements.Length > 0 Then
  10:              Using conn As New SqlConnection()
  11:                  conn.ConnectionString = connectionString
  12:                  conn.Open()
  13:   
  14:                  Using command As New SqlCommand(String.Empty, conn)
  15:                      For Each statement As String In statements
  16:                          command.CommandText = statement
  17:                          command.ExecuteNonQuery()
  18:                      Next
  19:                  End Using
  20:              End Using
  21:          End If
  22:      End Sub
  23:   
  24:  #End Region

Ciao, alla prossima! Ogni tanto lasciatemi un salutino...

Currently rated 5.0 by 3 people

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

Posted by enrico on Friday, October 17, 2008 1:40 PM
Permalink | Comments (0) | Post RSSRSS comment feed