|
Hey guys,
Easy one here. I want to see the results of my datatable in the DataGridView. When i execute, it runs without errors but no DataGridView shows up on screen. Does DataGridView require a form to view the results or something?
What am I missing?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FileHelpers;
using System.Data;
using System.IO;
using System.Data.OleDb;
using System.Windows.Forms;
namespace CSVParser
{
class CSVParser
{
public static DataTable ParseCSV(string path)
{
if (!File.Exists(path))
return null;
string full = Path.GetFullPath(path);
string file = Path.GetFileName(full);
string dir = Path.GetDirectoryName(full);
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;"
+ "Data Source=\"" + dir + "\\\";"
+ "Extended Properties=\"text;HDR=No;FMT=Delimited\"";
string query = "SELECT * FROM " + @"C:\Users\rsharp\Desktop\CustomerExport.csv";
DataTable dTable = new DataTable();
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
dAdapter.Fill(dTable);
DataGridView dgView = new DataGridView();
BindingSource bSource = new BindingSource();
bSource.DataSource = dTable;
dgView.DataSource = bSource;
dAdapter.Dispose();
return dTable;
}
}
}
modified 21-Nov-12 19:21pm.
|
|
|
|
|
RickSharp wrote: Doesn DataGridView require a form to view the results or something?
Yes, it does. It needs to be assigned to the Controls collection of the form that it's supposed to show on.
Where's the entry-point of your application?
|
|
|
|
|
By entry point do you mean is it just a win form, exe or class library? If so I have added a form project and console application project to my solution. So I have a class library that contains that code. I added a reference to that class library in the new forms and console projects that I created. I tried following this tutorial with no success.
http://www.dotnetperls.com/datagridview-tutorial[^]
|
|
|
|
|
RickSharp wrote: By entry point do you mean is it just a win form, exe or class library? If so I have added a form project and console application project to my solution. So I have a class library that contains that code. I added a reference to that class library in the new forms and console projects that I created. I tried following this tutorial with no success.
The tutorial has some different code than you have; A console-application doesn't show a form usually. There's also no need for a separate class-library - simply put then in a normal forms-application.
|
|
|
|