Advertisement
SoundSoul

sqlCsharpUlploadCols

Nov 22nd, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using MySql.Data.MySqlClient;
  7. using System.IO;
  8.  
  9. namespace kurvalaci
  10. {
  11.     class Program
  12.     {
  13.         static MySqlConnection conn = new MySqlConnection(
  14.             "Server=winsql.vereb.dc;" +
  15.             "Database=diak52;"+
  16.             "Uid=diak52;"+
  17.             "Pwd=5EebEM;"
  18.             );
  19.  
  20.         static void Main(string[] args)
  21.         {
  22.            
  23.             /*var adapter = new MySqlDataAdapter();
  24.             adapter.SelectCommand = new MySqlCommand("SHOW TABLES", conn);
  25.             var reader = adapter.SelectCommand.ExecuteReader();
  26.             while (reader.Read())
  27.             {
  28.                 Console.WriteLine(reader[0]);
  29.             }*/
  30.             Feltolt();
  31.            
  32.             Console.ReadKey();
  33.         }
  34.         private static void Feltolt()
  35.         {
  36.            
  37.             var sr = new StreamReader("lopott_adatok.txt",Encoding.UTF8);
  38.             conn.Open();
  39.            
  40.             string[] os = sr.ReadLine().Split('\t');
  41.             var sql = $"INSERT INTO filmek({os[1]} , {os[2]} , {os[3]} , {os[4]}) VALUES ";
  42.             sr.ReadLine();
  43.             while (!sr.EndOfStream)
  44.             {
  45.                 var t = sr.ReadLine().Split('\t');
  46.                 sql += $"('{t[1].Replace("\'","\'\' ")}','{t[2]}','{t[3]}','{t[4]}'), ";
  47.  
  48.            }
  49.            sql = sql.TrimEnd(',', ' ') + ';';
  50.            var adapter = new MySqlDataAdapter();
  51.            adapter.InsertCommand = new MySqlCommand(sql, conn);
  52.            adapter.InsertCommand.ExecuteNonQuery();
  53.            conn.Close();
  54.        }
  55.    }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement