Illustrates simple stored procedures with unnamed parameters in the query
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);
con.Open();
Console.WriteLine("Made the connection to the database");
OleDbCommand cmd = con.CreateCommand();
cmd.CommandText ="SELECT First_name FROM Employee WHERE ID = ?";
OleDbParameter param = new OleDbParameter();
cmd.Parameters.Add(param);
param.Value = "01";
OleDbDataReader reader = cmd.ExecuteReader();
Console.WriteLine("Using a stored procedure");
while(reader.Read())
Console.WriteLine("{0}", reader.GetString(0));
reader.Close();
param.Value = "01";
reader = cmd.ExecuteReader();
Console.WriteLine("Using a stored procedure");
while(reader.Read())
Console.WriteLine("{0}", reader.GetString(0));
reader.Close();
con.Close();
}
}
Related examples in the same category