CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2002
    Location
    USA
    Posts
    2

    Post How to read records from a database

    Can someone show me how to read all the records from a database?

    Here's what i have:
    ---
    MyCommand.CommandText = "SELECT * FROM swdata";
    OdbcDataReader MyDataReader;
    MyDataReader = MyCommand.ExecuteReader();

    < what code goes in here?>

    MyDataReader.Close();
    MyConnection.Close();
    ---

    thanks
    -mttomb-

  2. #2
    Join Date
    Jun 2002
    Location
    Philadelphia, PA
    Posts
    85

    Re: How to read records from a database

    Originally posted by mttomb
    Can someone show me how to read all the records from a database?

    Here's what i have:
    ---
    MyCommand.CommandText = "SELECT * FROM swdata";
    OdbcDataReader MyDataReader;
    MyDataReader = MyCommand.ExecuteReader();

    < what code goes in here?>

    MyDataReader.Close();
    MyConnection.Close();
    ---

    thanks
    Assuming your connection is opened properly and everything else in order, you simply do as follows:

    Code:
    MessageBox.Show(MyDataReader[MyFieldName]);
    Now, unfortunately, you cannot use this for write access. For write access, you need to use Datasets and DataAdapters. Let me know if you need any code to example that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured