mel C

mel C

  • NA
  • 8
  • 0

OleDb query with positioned parameter

Jan 5 2009 4:33 AM

Hi,

I'm a newbie in C#, I wrote an OLEDb query with positioned parameter. It seems not working. Can anyone please point out where I've done wrong? Thanks in advance.

Here is my code:

using (OleDbConnection conn = new OleDbConnection(connString))

{

              String key = textbox1.text;

              string cmd = "Select * from [" + filename + "] Where " + fieldname + " like ?";

              OleDbCommand command= new OleDbCommand(cmd, conn);

              OleDbParameter parameter = new OleDbParameter("@key",OleDbType.VarChar,30);

             parameter.Value = "'%"+key+"%'";

            command.Parameters.Add(parameter);

           conn.Open();

          OleDbDataAdapter dataAdapter = new OleDbDataAdapter(cmd, conn);

          OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(dataAdapter);

          DataTable table = new DataTable();        

         table.Locale = System.Globalization.CultureInfo.InvariantCulture;

        dataAdapter.Fill(table);

} 


Answers (3)