Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Tue, 30 Mar 2004 @ 10:29:46 GMT


     
  <Prev Next>   <<First <Prev
Next>
Last>>
 


Subj:   Re: Stored Procedures and C#
 
From:   Anomy Anom

<-- Anonymously Posted: Tuesday, March 30, 2004 02:36 -->

I agree it's a work around, but the code below seems to work for this stored procedure.

replace procedure TESTDB.TestProc(IN pIn INTEGER,  INOUT pOut INTEGER)
BEGIN

SET pOut = pOut + (pIn * 2);

END;



using System;
using Microsoft.Data.Odbc;
using System.Data;

namespace storedProc2
{
      class Class1
      {
            [STAThread]
            static void Main(string[] args)
            {
                  string myConnection = "DSN=TD_testDB;UID=user;PWD=pass";
                  OdbcConnection myConn = new OdbcConnection(myConnection);

                  string myTestQuery = "call TESTDB.TestProc(?,?)";

                  OdbcCommand sampleCMD = new OdbcCommand(myTestQuery);
                  sampleCMD.Connection = myConn;

                  OdbcParameter prm = sampleCMD.Parameters.Add("pIn", OdbcType.Int);
                  prm.Value = 34;
                  prm.Direction = ParameterDirection.Input;

                  prm = sampleCMD.Parameters.Add("pOut", OdbcType.Int);
                  prm.Value = 40;
                  prm.Direction = ParameterDirection.Input;


Console.WriteLine(sampleCMD.Parameters[0].ParameterName + " = " + sampleCMD.Parameters[0].Value.ToString());

                  try
                  {
                        myConn.Open();
                        Console.WriteLine(sampleCMD.CommandText);
                        OdbcDataReader r = sampleCMD.ExecuteReader();

                        while (r.Read())
                        {
                              int pOut = r.GetInt32(0);
                              System.Console.WriteLine("pOut = " + pOut.ToString());
                        }

                        r.Close();
                        myConn.Close();
                  }

                  catch(Exception e)
                  {
                        Console.WriteLine(e.ToString());
                        Console.Read();
                  }
                  finally
                  {
                        if (myConn.State == ConnectionState.Open)
                              myConn.Close();
                  }
                        Console.Write("Press any key to end...");
                        Console.Read();

            }
      }
}


     
  <Prev Next>   <<First <Prev
Next>
Last>>
 
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023