CSharp Call Store Procedure Through Olddbconnection In C# – ADO.Net Database

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script Language="c#" runat="server">
  void Page_Load(object sender, EventArgs e)
    OleDbConnection objConnection = null;
    OleDbCommand objCmd = null;
    string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
    strConnection += @"Data Source=C:\Northwind.mdb";
    // Create and open the connection object
    objConnection = new OleDbConnection(strConnection);
    // Create the Command and set its properties
    objCmd = new OleDbCommand();
    objCmd.Connection = objConnection;
    objCmd.CommandText = "[Sales by Category]";
    objCmd.CommandType = CommandType.StoredProcedure;
    dgSales.DataSource = objCmd.ExecuteReader(CommandBehavior.CloseConnection);
    <h2>Using a stored procedure</h2>
    <asp:datagrid id="dgSales" runat="server" />

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.