Convertir un fichier .txt en un fichier .sql
Bonjour,
J'ai pour projet de convertir un fichier texte (qui sera afficher par importation préalablement sur un label sur l'interface graphique Window Forms), où il y a :
CodeC;NomC;AdresseC;VilleC;CPC;TelC
C1;SF Belleville;;Verdun;55100;
C2;SCA Epinal;;Epinal;88000;
C3;USL Mineenne;;St Mihiel;55300;
C4;FC Toul;;Toul;54200;
C5;US Etain;;Etain;55400;
C6;ESP Lunéville;;Lunéville;54300;
C7;FC Velaines;;Velaines;55500;
C8;FCSTD;;Saint Dié;88100;
C9;District Vosges;;Epinal;88000;
C10;FC Val Dunois;;Behonne;55000;
C11;FC Bruch Forbach;;Forbach;76000;
C12;FC Commercy;;Velaines;55500;
Directement dans un label à côté (converti en SQL) en appuyant sur un bouton convertir.
J'ai programmé le fait d'enregistrer le fichier en .sql en appuyant sur un bouton "Save..."
Où j'en suis :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace fichiers
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string path = "..\\..\\..\\";
string path2 = path;
string nomFichier = "listeSIO1A.txt";
path = path + nomFichier;
}
private void btnDriveInfo_Click(object sender, EventArgs e)
{
DriveInfo[] drives = DriveInfo.GetDrives();
foreach(DriveInfo unDrive in drives)
{
if (unDrive.IsReady)
{
MessageBox.Show(unDrive.Name.ToString() + " " + unDrive.DriveType.ToString() + unDrive.TotalSize.ToString() + " " + unDrive.TotalFreeSpace.ToString());
}
else
{
MessageBox.Show(unDrive.Name.ToString() + " " + unDrive.DriveType.ToString());
}
}
}
private void FBD_Click(object sender, EventArgs e)
{
if (FBD.ShowDialog() == DialogResult.OK)
{
txbDossier.Text = FBD.SelectedPath;
}
}
private void btnOFD_Click(object sender, EventArgs e)
{
String ligne;
OFD.Title = "Les fichiers texte."; //titre de la boite de dialogue
OFD.Filter = "Fichiers texte|*.txt";// Filtre : n'affiche que les fichiers ".txt"
if (OFD.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
try
{
lbxFichiers.Items.Clear(); // vider la listbox
StreamReader SR = new StreamReader(OFD.OpenFile()); // Ouvrir le flux en lecture
while ((ligne = SR.ReadLine()) != null) //lire le fichier ligne par ligne
{
lbxFichiers.Items.Add(ligne); // copier les lignes du fichier dans la listBox
}
SR.Close(); // fermer le flux
}
catch
{
MessageBox.Show("Erreur: Lecture du fichier impossible");
}
}
}
private void btnSFD_Click(object sender, EventArgs e)
{
SFD.InitialDirectory = @"C:\";
SFD.DefaultExt = "sql";
SFD.ShowDialog();
if (SFD.FileName != "")
{
StreamWriter fsWriter = new StreamWriter(SFD.OpenFile());
fsWriter.Write(lbxSql.Text);
fsWriter.Close();
fsWriter.Dispose();
}
}
private void btnConvert_Click(object sender, EventArgs e)
{
}
private void lbxFichiers_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
} |
Merci de votre future aide !