Re: ODBCDataReader dBase IV

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Kevin Ghantous (anonymous_at_discussions.microsoft.com)
Date: 04/06/04


Date: Tue, 6 Apr 2004 11:31:10 -0700

Paul,

Below you will find a code snippit. Now, one thing I was thinking about as I was gathering this snippit, I am storing the reader in an IDataReader type instead of the ODBCDataReader type. I am going to go ahead and post this code, but I will try to change the type to an ODBCDataReader. I will let you know what happens. -- My code is relatively the same, I simply have a different ConnectionString...

[Code]
ConnectionString: DRIVER={Microsoft dBase Driver (*.dbf)};DBQ=C:\Documents and Settings\ghantousk\Desktop\Ghantous\DATAFILE;DefaultDir=C:\Documents and Settings\ghantousk\Desktop\Ghantous;DriverId=277;MaxBufferSize=2048;PageTimeout=5;

Odbc.OdbcConnection dbConn = new Odbc.OdbcConnection(ConnectionString);
Odbc.OdbcCommand dbCmd = new Odbc.OdbcCommand("SELECT * FROM User WHERE LTrim(ID) = @ID",dbConn);
IDataReader dbReader;

dbCmd.Parameters.Add("@ID", "1234");

_connection.Open(); //Open Connection
dbCmd.Prepare(); //Pre-Compile Query
dbReader = dbCmd.ExecuteReader(CommandBehavior.CloseConnection);

if(dbReader.Read())
    Response.Write(dbReader["LastName"].ToString());

dbConn.Close()

Thanks,
-Kevin