Eseguire una script SQL (Run a script SQL)

by enrico 17. October 2008 13:40

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

Tags: , , , ,

vb.net | Tricks & Tips | Work around | sql

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by Esia Software 1.4.0.0

Informazioni sull'autore

Sono un cittadini di Trieste, ho 33 anni e faccio lo sviluppatore nella mia azienda che si chiama Esia Software.

Commenti recenti

Comment RSS

Post recenti

Calendar

<<  May 2012  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

Info legali

Le opinioni espresse in questo blog sono strettamente personali e ogni persona è responsabile dei commenti che inserisce.

RecentComments

Comment RSS