The full data source is in that format (meaning seperated with \\ ) and the coloumn name is correct and that is the name of the table. Can anyone tell me what I'm doing wrong?
You need to call the OleDbDataReader.Read method before accessing the row data. Also, be sure to close the resources after you are finished with them. A 'using' block is a handy way to do this.
Code:
String connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source = C:\\Users;Extended Properties =dBase IV;";
using( var dBaseConnection = new OleDbConnection(connectionString) )
{
dBaseConnection.Open();
using( OleDbCommand dBaseCommand = new OleDbCommand("SELECT FPHONE FROM ADDRESS", dBaseConnection) )
{
OleDbDataReader dBaseDataReader = dBaseCommand.ExecuteReader(CommandBehavior.SequentialAccess);
while( dBaseDataReader.Read( ) )
{
// retrieve the string from column 0 (NOTE: if the query returns
// more than one record, all faxnum will be overwritten except
// the last one
txtFaxNum.Text = dBaseDataReader.GetString( 0 );
}
}
}
Bookmarks