Click here to Skip to main content
15,914,379 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Expert

Just need a little help i don't know what I miss on the code
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string connStr = "server=localhost;userid=root;database=bdhapp";
     
                // MySql Connection Object
                MySqlConnection conn = new MySqlConnection(connStr);

                //  csv file path
                string file = @"filepath";

                // MySQL BulkLoader
                MySqlBulkLoader bl = new MySqlBulkLoader(conn);
                bl.TableName = "bdhtable";
                bl.FieldTerminator = "|"; 
                bl.LineTerminator = "\n";
                bl.FileName = file;

                try
                {
                    Console.WriteLine("Connecting to MySQL...");
                    conn.Open();

                    // Upload data from file
                    int count = bl.Load();
                    Console.WriteLine(count + " lines uploaded.");

                    conn.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                Console.WriteLine("Done.");
                Console.ReadLine();

            }

        }
    }
it doesn't run properly

What I have tried:

I tried other solution but it doesn't run the code
Posted
Comments
Richard MacCutchan 30-Sep-17 4:12am    
Your filename does not look valid. Is 'filepath' a real .csv file?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900