Click to See Complete Forum and Search --> : How to read records from a database


mttomb
July 4th, 2002, 09:01 AM
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

CPCericola
July 7th, 2002, 06:50 PM
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:


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.