tags:

views:

79

answers:

1

hi

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

+2  A: 

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
Winston Smith
+1 for the using suggestion
phsr