Learn .Net WPF from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Read CSV data using ODBC Connection

22/03/2017 0 0

Codes to read the CSV data using ODBC Connection-

Input File:

File's Encoding format should be ANSI as below

class Student
     public string CollegeId { get; set; }
     public string AdmissionDate { get; set; }
     public string CandidateId { get; set; }
     public string MobileNum { get; set; }


On the button Click I am calling the code to read the CSV data 

private void btnTest_Click(object sender, RoutedEventArgs e)
    string fileName = @"CSVData.csv";

    //Create a ODBC TEXT File connection
    string connectionString = "Driver={Microsoft Text Driver (*.txt;     *.csv)};defaultdir=tempFolder;driverid=27;extensions=csv;
fil=text;maxbuffersize=2048;pagetimeout=5".Replace(" tempFolder", @"C:\Personal\TrialApps\");

     string query = string.Format("SELECT * FROM `{0}`", fileName);

     List lstStudentInfo = new List();
     using (var odbcConnection = new OdbcConnection(connectionString))
       using (var odbcCommand = new OdbcCommand(query, odbcConnection))
           var dataReader = odbcCommand.ExecuteReader(CommandBehavior.CloseConnection);
           while (dataReader.Read())
             string college_id=dataReader["COLLEGE_ID"].ToString();
             string admission_date = dataReader["ADMISSION_DATE"].ToString();
             string candidate_id = dataReader["CANDIDATE_ID"].ToString();
             string mobile_num = dataReader["MOBILE_NUM"].ToString();
             lstStudentInfo.Add(new Student() { CollegeId=college_id,AdmissionDate=admission_date,
    dtGridCSVData.ItemsSource = lstStudentInfo;

Xaml Code for the UI Grid: 



0 Dislike
Follow 0

Please Enter a comment


Other Lessons for You

C-Program Swapping Contents Of Variables Using Function [Call By Reference Method]
//Header Files #include#include // User defined functions swap with 2 pointer variables passed as an argument list void swap(int*i,int*j){ // Local variable temp int temp; // swapping contents using...

What is DBMS and RDBMS
Database Management Systems A database is a collection of data or records. Database management systems are designed to work with data. A database management system (DBMS) is a software system that uses...

Create Immutable Class
Snippet of an Immutable Class: package com.stringhr; /*Declare the class as 'final'. This would prevent any other class from extending it and hence from overriding any method from it which could modify...

Looking for .Net WPF ?

Learn from Best Tutors on UrbanPro.

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you

Looking for .Net WPF Classes?

The best tutors for .Net WPF Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn .Net WPF with the Best Tutors

The best Tutors for .Net WPF Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more