Illustrates simple stored procedures with unnamed parameters in the query : Store Procedure « Database ADO.net « C# / C Sharp






Illustrates simple stored procedures with unnamed parameters in the query

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

1.Add parameters to SqlCommand to call stored procedure
2.Call the SQL Server AddProduct() stored procedure with SqlCommand
3.Populate a DataSet object using a store procedure
4.Call the SQL Server AddProduct() store procedure
5.Get Return from SQL Server store procedure
6.Call Simple Store Procedure
7.illustrates how to call a SQL Server stored procedure
8.Call a store procedure