Torna al Thread

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Sql; using System.Data.SqlClient; using System.IO; using System.Drawing; using System.Text; using System.Windows.Forms; namespace esport { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //lettura dati del database string record = ""; string lettura = "select * from NOME TABELLA"; SqlConnection conn = new SqlConnection('STRINGA DI CONNESSIONE'); conn.Open(); SqlCommand command = new SqlCommand(lettura, conn); SqlDataReader leggi = command.ExecuteReader(); //creazione e scrittura del file di testo FileStream file = new FileStream(@"C:\export.txt", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new StreamWriter(file); while (leggi.Read()) { record = leggi[0].ToString() + " " + leggi[1] + " " + leggi[n] + "\n"; sw.Write(record); } conn.Close(); sw.Close(); file.Close(); } } }
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5