dear friend, in the next code i have a problem with the word 'DataTable', is this beacause DataTable appear content in 'using System.Data;' and 'using Autodesk.AutoCAD.DatabaseServices;':
help me please, the code is:
using Autodesk.AutoCAD.DatabaseServices;
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;
// HOW TO IMPORT EXCEL FILE TO DATAGRIDVIEW AND SAVE TO DATABASE USING C#
// using Microsoft.Office.Interop.Excel;
// C# Tutorial - Open and Read Excel Files (*.xls/*.xlsx) | FoxLearn
using ExcelDataReader;
using System.IO;
//using System.Data;
namespace DisanV01.Forms
//namespace DisanV01
{
public partial class UI_Inicio02_MetodoDeHunter : UserControl
{
public UI_Inicio02_MetodoDeHunter()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void cboSheet_SelectedIndexChanged(object sender, EventArgs e)
{
DataTable dt = tableCollection[cboSheet.SelectedItem.ToString()];
// dataGridView1.datasource
// dataGridView1.DataSource = dt;
dataGridView1.DataSource = dt;
}
private void button3_Click(object sender, EventArgs e)
{
}
DataTableCollection tableCollection;
private void inicio_metododehunter_004_btnImport_Click(object sender, EventArgs e)
{
//HOW TO IMPORT EXCEL FILE TO DATAGRIDVIEW AND SAVE TO DATABASE USING C#
//Microsoft.Office.Interop.Excel.Application xlApp;
//Microsoft.Office.Interop.Excel.Workbook xlWorkbook;
//Microsoft.Office.Interop.Excel.Worksheet xlWorksheet;
//Microsoft.Office.Interop.Excel.Range xlRange;
//int xlRow;
//string strFileName;
//openFD.Filter = "Excel Office |*.xls; *.xlsx";
//openFD.ShowDialog();
//strFileName = openFD.FileName;
//if(strFileName != "")
//{
// xlApp = new Microsoft.Office.Interop.Excel.Application();
// xlWorkbook = xlApp.Workbooks.Open(strFileName);
// xlWorksheet = xlWorkbook.Worksheets["Hoja1"];
// xlRange = xlWorksheet.UsedRange;
// int i = 0;
// for (xlRow = 2; xlRow <= xlRange.Rows.Count; xlRow++)
// {
// i++;
// inicio_metododehunter_006.Rows.Add(i, xlRange.Cells[xlRow, 1].Text, xlRange.Cells[xlRow, 2].Text);
// }
// xlWorkbook.Close();
// xlApp.Quit();
//}
// C# Tutorial - Open and Read Excel Files (*.xls/*.xlsx) | FoxLearn
{
using(OpenFileDialog openFD=new OpenFileDialog() { Filter= "Excel 97-2003 Workbook|*.xls|Excel Workbook|*.xlsx" })
{
if (openFD.ShowDialog() == DialogResult.OK)
{
txtFilename.Text = openFD.FileName;
using(var stream=File.Open(openFD.FileName, FileMode.Open, FileAccess.Read))
{
using (IExcelDataReader reader = ExcelReaderFactory.CreateReader(stream))
{
DataSet result = reader.AsDataSet(new ExcelDataSetConfiguration()
{
ConfigureDataTable = (_) => new ExcelDataTableConfiguration() { UseHeaderRow = true }
});
tableCollection = result.Tables;
cboSheet.Items.Clear();
foreach (DataTable table in tableCollection)
cboSheet.Items.Add(table.TableName);
}
}
}
}
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
}
}