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
[364 byte] By [
mttomb] at [2007-11-17 17:06:55]

# 1 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:
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.