Click here to Skip to main content
11,409,097 members (58,517 online)
   

C#

 
QuestionDataGridView doesn't appear on screen [modified] PinmemberRickSharp21-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);
 
            //try
           // {
                //fill the DataTable
                dAdapter.Fill(dTable);
           // }
            //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
            dAdapter.Dispose();
 
            return dTable;
        }
    }
}
 


modified 21-Nov-12 19:21pm.

AnswerRe: DataGridView doesn't appear on screen PinmemberEddy Vluggen21-Nov-12 14:17 
GeneralRe: DataGridView doesn't appear on screen PinmemberRickSharp21-Nov-12 14:27 
GeneralRe: DataGridView doesn't appear on screen PinmemberEddy Vluggen21-Nov-12 14:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web01 | 2.8.150414.5 | Last Updated 25 Apr 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid