Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Call Stored Procedure Using C#

Call Stored Procedure Using C#

Scheduled Pinned Locked Moved C#
csharpdatabasehelp
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Phil Saville
    wrote on last edited by
    #1

    Hi, im new to using stored procedures and i have the following stored procedure... CREATE OR REPLACE PROCEDURE DRL_PROCEDURE2(var_SOURCE_OBJECTID IN varchar2, var_NEW_OBJECTID OUT varchar2) AS BEGIN SELECT MAX(NEW_OBJECTID) INTO var_NEW_OBJECTID FROM DRL_CONVERSION WHERE SOURCE_OBJECTID = var_SOURCE_OBJECTID; END; I want to be able to call this procedure from my windows form application and display the result of the stored procedure into a label or a datagrid using C#...could someone please help me! Thanks in advance!

    A V P M 4 Replies Last reply
    0
    • P Phil Saville

      Hi, im new to using stored procedures and i have the following stored procedure... CREATE OR REPLACE PROCEDURE DRL_PROCEDURE2(var_SOURCE_OBJECTID IN varchar2, var_NEW_OBJECTID OUT varchar2) AS BEGIN SELECT MAX(NEW_OBJECTID) INTO var_NEW_OBJECTID FROM DRL_CONVERSION WHERE SOURCE_OBJECTID = var_SOURCE_OBJECTID; END; I want to be able to call this procedure from my windows form application and display the result of the stored procedure into a label or a datagrid using C#...could someone please help me! Thanks in advance!

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      Just google ADO.NET, there are thousands of examples

      Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

      1 Reply Last reply
      0
      • P Phil Saville

        Hi, im new to using stored procedures and i have the following stored procedure... CREATE OR REPLACE PROCEDURE DRL_PROCEDURE2(var_SOURCE_OBJECTID IN varchar2, var_NEW_OBJECTID OUT varchar2) AS BEGIN SELECT MAX(NEW_OBJECTID) INTO var_NEW_OBJECTID FROM DRL_CONVERSION WHERE SOURCE_OBJECTID = var_SOURCE_OBJECTID; END; I want to be able to call this procedure from my windows form application and display the result of the stored procedure into a label or a datagrid using C#...could someone please help me! Thanks in advance!

        V Offline
        V Offline
        Vimalsoft Pty Ltd
        wrote on last edited by
        #3

        Coding an N-Tier Application in C# Without Any Wizard: Part II[^]

        Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

        1 Reply Last reply
        0
        • P Phil Saville

          Hi, im new to using stored procedures and i have the following stored procedure... CREATE OR REPLACE PROCEDURE DRL_PROCEDURE2(var_SOURCE_OBJECTID IN varchar2, var_NEW_OBJECTID OUT varchar2) AS BEGIN SELECT MAX(NEW_OBJECTID) INTO var_NEW_OBJECTID FROM DRL_CONVERSION WHERE SOURCE_OBJECTID = var_SOURCE_OBJECTID; END; I want to be able to call this procedure from my windows form application and display the result of the stored procedure into a label or a datagrid using C#...could someone please help me! Thanks in advance!

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          That's not a procedure; it's just a simple query. I'd pass it to ExecuteScalar, that's what it's for. As the other person said; read up on ADO.NET.

          1 Reply Last reply
          0
          • P Phil Saville

            Hi, im new to using stored procedures and i have the following stored procedure... CREATE OR REPLACE PROCEDURE DRL_PROCEDURE2(var_SOURCE_OBJECTID IN varchar2, var_NEW_OBJECTID OUT varchar2) AS BEGIN SELECT MAX(NEW_OBJECTID) INTO var_NEW_OBJECTID FROM DRL_CONVERSION WHERE SOURCE_OBJECTID = var_SOURCE_OBJECTID; END; I want to be able to call this procedure from my windows form application and display the result of the stored procedure into a label or a datagrid using C#...could someone please help me! Thanks in advance!

            M Offline
            M Offline
            Mark Graham
            wrote on last edited by
            #5

            Here's a helper class I use. It's lightweight but contains a few useful methods. Create a new class in your project and call it 'DbAssist' and copy this code in there. I haven't documented the methods so if you have trouble understanding anything just reply and I will assist. Cheers

            using System;
            using System.Configuration;
            using System.Data;

            namespace Common.Data {

            public static class DbAssist {
            
                private static void CheckConnectionClosed(IDbConnection connection) {
                    if (connection.State != ConnectionState.Closed) {
                        throw new InvalidOperationException("An error has occurred: connection is not in closed state.");
                    }
                }
            
                // Connection help
            
                public static string GetConnectionString(string key) {
                    try {
                        return ConfigurationManager.ConnectionStrings\[key\].ConnectionString;
                    } catch (NullReferenceException ex) {
                        throw new ConfigurationErrorsException("An error has occurred: "
                            + key + " does not exist in config.", ex);
                    }
                }
            
                // Scalar help
            
                public static object ExecScalar(string sqlText, IDbConnection connection) {
                    return ExecScalar(sqlText, connection, CommandType.Text);
                }
            
                public static object ExecScalar(string sqlText, IDbConnection connection, CommandType cmdType) {
                    return ExecScalar(sqlText, connection, cmdType, null);
                }
            
                public static object ExecScalar(string sqlText, IDbConnection connection,
                        CommandType cmdType, IDataParameter\[\] parameters) {
                    CheckConnectionClosed(connection);
                    using (connection) {
                        connection.Open();
                        IDbCommand command = connection.CreateCommand();
                        command.CommandText = sqlText;
                        command.CommandType = CommandType.StoredProcedure;
                        if (parameters != null) {
                            foreach (IDataParameter p in parameters) {
                                command.Parameters.Add(p);
                            }
                        }
                        return command.ExecuteScalar();
                    }
                }
            
                // IDataReader help
            
                public static IDataReader ExecReader(string sqlText, IDbConnection connection) {
                    return ExecReader(sqlText, connection, CommandBehavior.CloseConnection);
                }
            
                public static IDataReader ExecReader(string sqlText, IDbConnection connection,
            
            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups