Pass parameter to OleDbCommand : OleDbCommand « Database « C# / C Sharp

Pass parameter to OleDbCommand

Pass parameter to OleDbCommand
using System;
using System.Data;
using System.Data.OleDb;

public class Prepare {    
 public static void Main () { 
   String connect = "Provider=Microsoft.JET.OLEDB.4.0;data source=.\\Employee.mdb";
   OleDbConnection con = new OleDbConnection(connect);
   Console.WriteLine("Made the connection to the database");

   OleDbCommand cmd1 = con.CreateCommand();
   cmd1.CommandText = "SELECT ID FROM Employee "
                    + "WHERE id BETWEEN ? AND ?";
   OleDbParameter p1 = new OleDbParameter();
   OleDbParameter p2 = new OleDbParameter();
   p1.Value = "01";
   p2.Value = "03";
   OleDbDataReader reader = cmd1.ExecuteReader();
     Console.WriteLine("{0}", reader.GetInt32(0));


Related examples in the same category

1.Execute aggregate function: sumExecute aggregate function: sum
2.Get column averageGet column average
3.Get max column valueGet max column value
4.Get count value from a select queryGet count value from a select query
5.Between certain dates
6.Delete database records through OleDbCommand and verify the results
7.Create table and populate data
8.How to execute a TableDirect command