Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7894883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:30:26+00:00 2026-06-03T07:30:26+00:00

I have a method that retrieves all data from a specific column in a

  • 0

I have a method that retrieves all data from a specific column in a table. Now this method works when the fields are in “string” or “int” (by changing to GetInt32) formats in the database, although it doesn’t like date fields, my method is as follows:

public static void getDates()
{
    //create the database connection
    OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\ev_mgr.mdb");

    //create the command object and store the sql query
    OleDbCommand actorCommand = new OleDbCommand("select Issue_Time2 from Events", aConnection);
    try
    {
        aConnection.Open();

        //create the datareader object to connect to table
        OleDbDataReader aReader = actorCommand.ExecuteReader();

        //Iterate throuth the database
        while (aReader.Read())
        {
            timeList.Add(aReader.GetString(0)); // Error occurs here

        }

        //close the reader
        aReader.Close();

        //close the connection Its important.
        aConnection.Close();
    }

    //Some usual exception handling
    catch (OleDbException e)
    {
        Console.WriteLine("Error: {0}", e.Errors[0].Message);
    }


    foreach (string time in timeList)
    {
        Console.WriteLine(time);
    }
}

An exception is thrown on this line:

timeList.Add(aReader.GetString(0));

Error:

Specified cast is not valid.

An example of a date/field in the column is:

02/05/2012 15:52:45
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:30:27+00:00Added an answer on June 3, 2026 at 7:30 am

    try

    timeList.Add(aReader.GetDateTime(0).ToString());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have the following code that retrieves data from the database and then
I have three SQL Server databases that a single application retrieves data from. I
I have method in my BLL that interacts with the database and retrieves data
I have a WCF service method that expects an object and then retrieves its
I have this method that changes an larger image source on click. I need
I have a method that returns a list of type string. I want to
I have a method that will receive a string , but before I can
I have an ASP.NET web application that presents data retrieved from a web service.
I have a custom Android ContentProvider which stores and retrieves data from a SQLite
I have a method that calls a service to retrieve an instance of an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.