Call Stored Procedure Using C#
-
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!
-
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!
-
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!
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/
-
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!
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.
-
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!
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,