-2

It's basically a system connected with Arduino, you can use your schoolcard to link with the system, when you are linked you can use the printers or the 3d printers.

The database-to-excel exportation already works but not the import-to-database function.

Code:

    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 Excel = Microsoft.Office.Interop.Excel;

    namespace HTC_toestemming_systeem_V1
    {
        public partial class ImportFromExcel : Form
        {
            //doesnt work
             private string openLocation;
             public int columns { get; set; }
             public int rows { get; set; }

        public ImportFromExcel()
        {
            InitializeComponent();
        }

        private void Kies_Folder_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog sfd = new OpenFileDialog())
            {
                selectFile:
                sfd.Title = "Selecteer een bestand";
                sfd.Filter = "Excel bestand (*.xls)|*.xls";

                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    openLocation = sfd.FileName;
                    label1.Text = openLocation;
                }
                else
                {
                    if (MessageBox.Show("Geen locatie geselecteerd!\n\nWil je alsnog een locatie selecteren ?", "Dan niet", MessageBoxButtons.RetryCancel, MessageBoxIcon.Information) == DialogResult.Retry)
                    {
                        goto selectFile;
                    }
                    return;
                }
            }
        }

        private void Lees_Excel_Click(object sender, EventArgs e)
        {
            //gebruikt de Excel.cs bestand
            Excel_ excel = new Excel_(@openLocation, 1);
            int column = excel.columns;
            int row = excel.rows;
            //MessageBox.Show(column + " + " + row);
            //doet alles in een array
            string[,] read = excel.ReadRange(1, 1, row, column);
            excel.Close();
        }

        private void ImportFromExcel_Load(object sender, EventArgs e)
        {

        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
 }
halfer
  • 18,701
  • 13
  • 79
  • 158
memohtc
  • 1
  • 3
  • Maybe try implementing something before saying there is a problem. I think https://stackoverflow.com/questions/23041021/how-to-write-some-data-to-excel-file-xlsx is a good way to start – PilouPili Sep 06 '18 at 08:38

1 Answers1

0

I think the easiest way is to use the EPPlus library and load the content of the file into a DataTable and then you could use many ways to import the data into a database.

  • If you're trying to just insert the data into the DB you can use SqlBulkCopy.

Here some useful tutorials and resources:

Richard
  • 108
  • 2
  • 3
  • 10