Click here to Skip to main content
13,294,516 members (58,827 online)


QuestionDataGridView doesn't appear on screen Pin
RickSharp21-Nov-12 13:44
memberRickSharp21-Nov-12 13:44 
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; //not used by default
using System.IO; //not used by default
using System.Data.OleDb; //not used by default
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);
            //create the "database" connection string 
            string connString = "Provider=Microsoft.Jet.OLEDB.4.0;"
              + "Data Source=\"" + dir + "\\\";"
              + "Extended Properties=\"text;HDR=No;FMT=Delimited\"";
            //create the database query
            string query = "SELECT * FROM " + @"C:\Users\rsharp\Desktop\CustomerExport.csv";
            //create a DataTable to hold the query results
            DataTable dTable = new DataTable();
            //create an OleDbDataAdapter to execute the query
            OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
           // {
                //fill the DataTable
           // }
            //catch (InvalidOperationException /*e*/)
           // { }
            //the DataGridView
            DataGridView dgView = new DataGridView();
            //BindingSource to sync DataTable and DataGridView
            BindingSource bSource = new BindingSource();
            //set the BindingSource DataSource
            bSource.DataSource = dTable;
            //set the DataGridView DataSource
            dgView.DataSource = bSource;
            //Dispoe of the adapter
            return dTable;

modified 21-Nov-12 19:21pm.

AnswerRe: DataGridView doesn't appear on screen Pin
Eddy Vluggen21-Nov-12 14:17
memberEddy Vluggen21-Nov-12 14:17 
GeneralRe: DataGridView doesn't appear on screen Pin
RickSharp21-Nov-12 14:27
memberRickSharp21-Nov-12 14:27 
GeneralRe: DataGridView doesn't appear on screen Pin
Eddy Vluggen21-Nov-12 14:42
memberEddy Vluggen21-Nov-12 14:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Advertise | Privacy |
Web02 | 2.8.171207.1 | Last Updated 14 Dec 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid