Hi folks,
I am currently making a piece of software in c# which uses a very large .dbf (yuk!) database (about 120MB). I have a "Remote" class which is used to do the database operations. I use ODBC to connect to this database. All works, except that due to the size of the database, it takes very long for each lookup. For the use of this software, waiting up to 10 seconds for each item to display is not acceptable.
I'm kinda hoping that the problem lies in the fact that the database has to always be opened and closed so I would like to try and see if I could open the database at program startup and then just run the command.
The problem is, no matter what I try, I always get the error Error "The name 'oCmd' does not exist in the current context" and "The name 'oConn' does not exist in the current context".
This is the remote class which works:
public static class Remote
{
public static string GetData(string data,int c)
{
System.Data.Odbc.OdbcConnection oConn = new System.Data.Odbc.OdbcConnection();
oConn.ConnectionString = @"Driver={Microsoft dBase Driver (*.dbf)};SourceType=DBF;SourceDB=c:\database\;Exclusive=No; Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
oConn.Open();
System.Data.Odbc.OdbcCommand oCmd = oConn.CreateCommand();
oCmd.CommandText = @"SELECT * FROM c:\database\database.dbf WHERE CODE LIKE '" + data + "'";
DataTable dt = new DataTable();
dt.Load(oCmd.ExecuteReader());
oConn.Close();
//bla-bla--bla--following statements just extract the data from the datatable.
}
This is the remote class which doesn't work:
public static class Remote
{
public static void openDatabase()
{
System.Data.Odbc.OdbcConnection oConn = new System.Data.Odbc.OdbcConnection();
oConn.ConnectionString = @"Driver={Microsoft dBase Driver (*.dbf)};SourceType=DBF;SourceDB=c:\database\;Exclusive=No; Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
oConn.Open();
System.Data.Odbc.OdbcCommand oCmd = oConn.CreateCommand();
}
public static string GetData(string data,int c)
{
oCmd.CommandText = @"SELECT * FROM c:\database\database.dbf WHERE CODE LIKE '" + data + "'";
DataTable dt = new DataTable();
dt.Load(oCmd.ExecuteReader());
oConn.Close();
//bla-bla--bla--following statements just extract the data from the datatable.
}
The idea was to make the main Form call Remote.openDatabase() as startup. Then, some other class are to make use of Remote.GetData. But the 2 errors I mentioned appear.
Any ideas?
Your help is appreciated thanks