using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using MySql.Data.MySqlClient; using System.IO; namespace texttodb3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string[] lines = File.ReadAllLines("c:Users\\Techsoft\\Desktop\\db.txt"); foreach (var line in lines) { var data = line.Split(new[] { ',' }, 4); int Id = int.Parse(data[0].Trim()); int age = int.Parse(data[1].Trim()); string name = data[2].Trim(); StoreRecord(Id, age, name); } } private void StoreRecord(int Id, int age, string name) { var conStr = "server=localhost; database=neww; password=techsoft; User Id=root;"; using (var connection = new MySqlConnection(conStr)) using (var command = connection.CreateCommand()) { connection.Open(); command.CommandText = @"INSERT INTO neww (Id, age, name) VALUES (@Id, @age, @name)"; command.Parameters.AddWithValue("@Id", Id); command.Parameters.AddWithValue("@age", age); command.Parameters.AddWithValue("@name", name); command.ExecuteNonQuery(); } } } }
neww
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)