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
Re: How to read records from a database
Quote:
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.