Exemple #1
0
        private void InitialImporter()
        {
            switch (Source)
            {
            case DataSource.SqlServer: _dataImporter = new DataImporter(_sqlConnection); break;

            case DataSource.MySql: _dataImporter = new DataImporter(_mySqlConnection); break;
            }
        }
Exemple #2
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            if (!connected)
            {
                MessageBox.Show("Please connect to database server.");
                return;
            }
            if (!getDbList().Contains(comboBoxDbList.Text) || !getDtList().Contains(comboBoxDtList.Text))
            {
                DialogResult dialogResult = MessageBox.Show(@"Do you want create with the specified name?",
                                                            @"Database or table not exists", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.No)
                {
                    return;
                }
            }
            string dbname           = comboBoxDbList.Text == string.Empty ? "csv2db" : comboBoxDbList.Text;
            string dtname           = comboBoxDtList.Text == string.Empty ? "tb_from_csv" : comboBoxDtList.Text;
            string connectionString = "";

            switch (listBoxDatabase.SelectedIndex)
            {
            case 0:
            {
                connectionString = checkBoxIntegratedSecurity.Checked
                            ? $"Data Source={textBoxServer.Text};Initial Catalog=master;Persist Security Info=True;Integrated Security=True"
                            : $"Data Source={textBoxServer.Text};Initial Catalog=master;Persist Security Info=True;User ID={textBoxUId.Text};Password={textBoxPwd.Text}";
                DataImporter.DoWriteToSqlServer(dbname, dtname, connectionString, textBoxFilePath.Text, checkBoxIgnoreFirstLine.Checked);
            }
            break;

            case 1:
            {
                connectionString = $"server={textBoxServer.Text};user id={textBoxUId.Text};Password={textBoxPwd.Text};database=mysql";
                //DataImporter.ImportToMySqlAsync(dbname, dtname, connectionString, textBoxFilePath.Text, null, true);
                DataImporter.ImportToMySql(dbname, dtname, connectionString, textBoxFilePath.Text,
                                           checkBoxIgnoreFirstLine.Checked);
            }
            break;
            }
        }