Torna al Thread

Private Sub CreateCSV(ByVal filepath As String) Using objConn As New SqlConnection("Data Source=.; Initial Catalog=tempdb; Integrated Security=SSPI;") Using objCmd As New SqlCommand("SELECT Id, Nome, Cognome, Eta FROM Utenti", objConn) Using objDA As New SqlDataAdapter(objCmd) ' apro la connessione objConn.Open() Dim dt As New DataTable("risultati") objDA.Fill(dt) ' se il datatable ha righe creo il file If dt.Rows.Count > 0 Then Using sw As New StreamWriter(filepath) ' ciclo riga per riga For Each dr As DataRow In dt.Rows sw.Write("{0};{1};{2};{3}{4}", dr("Id"), dr("Nome"), dr("Cognome"), dr("Eta"), Environment.NewLine) Next ' chiudo gli oggetti objConn.Close() sw.Close() End Using End If End Using End Using End Using End Sub
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5