Gold
Gold

Reputation: 62524

help with C# code for fast search

i have this code that can do fast search on database.

it works excellent on sqlCE.

now i need to translate that it will work on Access 2007

how to do it ?

public bool LOOK()
        {
            Tmp = "";
            MAK = "";
            DES = "";
            Cmd.CommandType = CommandType.TableDirect;
            Cmd.CommandText = "BarcodeTbl";
            Cmd.IndexName = "Barcode";
            Cmd.SetRange(DbRangeOptions.Match, new object[] { txtYad.Text }, null);
            SqlCeDataReader read = Cmd.ExecuteReader();
            while (read.Read())
            {
                Tmp = read[2].ToString(); 
                MAK = read[0].ToString(); 
                DES = read[1].ToString();
            }
            read.Dispose();
            if (Tmp == "")
            {
                return false;
            }
            else
            {
                txtYad.Text = DES;
                return true;
            }
        }

thank's in advance

Upvotes: 1

Views: 243

Answers (1)

Winston Smith
Winston Smith

Reputation: 21912

You need to use the classes from the System.Data.OleDb namespace, for example OleDbDataReader, OleDbCommand etc.

As an aside, the following:

SqlCeDataReader read = Cmd.ExecuteReader();
while (read.Read())
 {
     Tmp = read[2].ToString(); 
     MAK = read[0].ToString(); 
     DES = read[1].ToString();
 }
 read.Dispose();

Can be better written as:

using(SqlCeDataReader read = Cmd.ExecuteReader())
{
    while (read.Read())
    {
        Tmp = read[2].ToString(); 
        MAK = read[0].ToString(); 
        DES = read[1].ToString();
     }
} // .Dispose() is called automatically here

Upvotes: 2

Related Questions