UrbanPro
true

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

Revan
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))
    {
       odbcConnection.Open();
       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,
                                                                 CandidateId=candidate_id,MobileNum=mobile_num});
          }
       }
    }
    dtGridCSVData.ItemsSource = lstStudentInfo;
}

Xaml Code for the UI Grid: 

Output:

Cheers!

0 Dislike
Follow 0

Please Enter a comment

Submit

Other Lessons for You

Technology learning Tip
To learn any technology especially related programming you need to think logically and need good practice time. Never try to start from scratch or start reading a book related to to learn a subject. ...

Format Date to “MM/dd/yyyy” in Webgrid ASP.Net MVC Razor View
Replace above line with below to apply ("DD/mm/yyyy") formatting to date field in WebGrid AllTicket.Column(columnName: "DueDate", header: "Due Date") grid.Column("Date",format:@<text> @item.Date.ToString("MM/dd/yyyy")</text>)
M

Mohammad Shafi

0 0
0

Database Genral Interview question
Q: What is SQL? A: SQL stands for 'Structured Query Language'. Q: What is SELECT statement? A: The SELECT statement...

Inversion of Control
Problem You have classes that have dependencies on services or components whose concrete type is specified at design time. In this example, ClassA has dependencies on ServiceA and ServiceB. Figure 1 illustrates...

How to learn or method of learning?
Friends,Now we will see what is learning definately you may feel that is this a question. we know very well becuase we already gone through that process i.e schools & college. But again i want to focus...
S

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
X

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