using System.Text.RegularExpressions;
public static void Main(string[] args){
String path = "data.csv";
File arqin = new File(path);
File arqout = new File(path+".sql");
MySqlConnection conexao = new MySqlConnection("server=localhost;database=newDb;user=root;password=");
private System.IO.StreamReader entrada;
private System.IO.StreamWriter saida;
public String getPath() {
public void setPath(String path) {
public System.IO.StreamReader openRead() {
var filestream = new System.IO.FileStream(path,
System.IO.FileAccess.Read,
System.IO.FileShare.ReadWrite);
this.entrada = new System.IO.StreamReader(filestream, System.Text.Encoding.UTF8, true, 128);
public System.IO.StreamWriter openWrite() {
saida = new System.IO.StreamWriter(path);
public String nextLine(){
return entrada.ReadLine();
private String[] lines = new String[20];
private System.IO.StreamReader entrada;
public void loadData(File arq) {
this.entrada = arq.openRead();
var dataRow = this.entrada.ReadLine();
string[] cols = Regex.Split(entrada.ReadLine(), "\r\n");
while ((line = entrada.ReadLine()) != null){
String[] dataArray = Regex.Split(line,";");
for (int i = 0; i < dataArray.Length; i++) {
if(colunas != "") colunas+=",";
colunas += "`"+ cols[i] +"`";
if(valores != "") valores+=",";
valores += "'"+ dataArray[i].Replace("'", "") +"'";
linha = "INSERT INTO tabela (" + colunas +
") VALUES (" + valores + ");";
for (int i = 0; i < dataArray.Length; i++) {
cols[i] = dataArray[i].Replace(' ', '_');
if(colunas != "") colunas+=",";
colunas += "`"+ dataArray[i].Replace(' ', '_') + "` VARCHAR(255)";
linha = "CREATE TABLE tabela ("+ colunas + ");";
dataRow = entrada.ReadLine();
public void saveData(MySqlConnection conn){
foreach(String l in this.lines){
Console.WriteLine(count);
public void saveData(File arq){
var saida = arq.openWrite();
foreach (string line in lines){
foreach(String s in lines){