Save excel data in SQL Server

0

In the image that is seen, it is a datagridview, the data is taken from an excel file, my question is how to pass this data to a table like this:

Usually to insert the records of a datagrid I use a foreach to read the data, but in this case, I do not know if it could be like putting a switch or something like that, because depending on the data, the numbers in the column num are changing, and I want to insert the records from the number that is in the column num, to say according to the data that is in the datagrid, these should be saved from the column T220 because the numbering begins from 22 and end in the 27 = T270

and this is the code I use:

private void btnImportar_Click(object sender, EventArgs e)
    {
        if (dgvExcel.RowCount != 0)
        {
            int programa = Convert.ToInt32(dgvExcel.CurrentRow.Cells[0].Value);
            int lote = Convert.ToInt32(dgvExcel.CurrentRow.Cells[1].Value);
            String modelo = Convert.ToString(dgvExcel.CurrentRow.Cells[4].Value);
            String color = Convert.ToString(dgvExcel.CurrentRow.Cells[5].Value);
            String linea = Convert.ToString(dgvExcel.CurrentRow.Cells[3].Value);
            String cliente = Convert.ToString(dgvExcel.CurrentRow.Cells[8].Value);
            int pedido = Convert.ToInt32(dgvExcel.CurrentRow.Cells[2].Value);
            DateTime fecha = Convert.ToDateTime(dgvExcel.CurrentRow.Cells[7].Value);

            //instruccion para mandar los datos a la clase que hace la insercion de datos
            biss.InfoLote(programa, modelo, color, linea, cliente, pedido, fecha.ToShortDateString());

            foreach (DataGridViewRow row in dgvExcel.Rows)
            {
                string fila = dgvExcel[0, row.Index].Value.ToString();
                if (fila != "")
                {
                    int T1 = Convert.ToInt32(dgvExcel[10, row.Index].Value);

                    //instruccion para mandar los datos a la clase que hace la insercion de datos
                    biss.DetalleLote(T150);
                }   
            }
        }
        else
        {
            MessageBox.Show("No ha seleecionado ningún archivo de Excel !!!");
        }
    }
    
asked by Macx 23.10.2018 в 18:31
source

0 answers