I'm just starting to learn C#, and I have this problem... How convert text to column in DataGridView from Excel source??
Source format:
NO BRAND NAME,ADRESS,PHONE
1 Brand1 Name1,adress1,phone1
2 Brand2 Name2,adress1,phone2
3 Brand1 Name3,adress3,phone3
4 Brand3 Name4,adress4,phone4
5 Brand1 Name5,adress5,phone5
6 Brand1 Name6,adress6,phone6
7 Brand4 Name7, adress7, phone7
8 Brand2 Name8,adress8,phone8
9 Brand4 Name9,adress9,phone9
10 Brand2 Name10,adress10,phone10
Excel sources: https://www.easypaste.org/file/dmqoMGDW/export-sources.xls?lang=en
I want the table after importing to look like this: enter image description here
Thx all for help me...
This is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ExceltoDGV
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog openfile1 = new OpenFileDialog();
if (openfile1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.textBox1.Text = openfile1.FileName;
string pathconn = "Provider = Microsoft.jet.OLEDB.4.0; Data source=" + textBox1.Text + ";Extended Properties=\"Excel 8.0;HDR= yes;\";";
OleDbConnection conn = new OleDbConnection(pathconn);
OleDbDataAdapter MyDataAdapter = new OleDbDataAdapter("Select * from [Inwestycje$]", conn);
DataTable dt = new DataTable();
MyDataAdapter.Fill(dt);
dataGridView1.DataSource = dt;
}
}
catch
{
}
}
}
}