Call Stored Procedure

Calling a stored procedure using c#

Page 1 of 1

6 Replies - 2464 Views - Last Post: 02 December 2009 - 08:25 PM Rate Topic: -----

#1 supersav144  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-December 09

Call Stored Procedure

Posted 01 December 2009 - 04:00 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: Call Stored Procedure

#2 karimi  Icon User is offline

  • Banned
  • member icon

Reputation: -9
  • View blog
  • Posts: 104
  • Joined: 29-May 09

Re: Call Stored Procedure

Posted 01 December 2009 - 09:26 AM

Write the code bellow:
{CODE REMOVED}
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Call Stored Procedure

Posted 01 December 2009 - 09:35 AM

@karimi: Once again we have a policy here that we show [b]no source code[/url] until the OP shows an effort (which this person did not do). I've had to say this to you before, please dont make me do it a third time :)

@supersav144
[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#4 MeSampath  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 13
  • Joined: 01-December 09

Re: Call Stored Procedure

Posted 01 December 2009 - 11:56 PM

Hi,

Calling the SQL Stored procedure in C# window application is pretty simple. Few ideas here;

1) Use SQL Connection to connect with the db.
2) Using SqlDataAdapter, create an object with assigning storedprocedure name and conn
for ex;
SqlDataAdapter ada = new SqlDataAdapter("<stored procedure name>",conn);

3) create a datatable and fill the datatable with adapter.fill method
4) assign the datatable to datagrid as datasource property.

Thats all. The results will be loaded in the grid.

Good luck.
Was This Post Helpful? 0
  • +
  • -

#5 supersav144  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-December 09

Re: Call Stored Procedure

Posted 02 December 2009 - 02:06 AM

View PostPsychoCoder, on 1 Dec, 2009 - 08:35 AM, said:

@karimi: Once again we have a policy here that we show [b]no source code[/url] until the OP shows an effort (which this person did not do). I've had to say this to you before, please dont make me do it a third time :)

@supersav144
[rules][/rules]


very sorry, i didn't realise
Was This Post Helpful? 0
  • +
  • -

#6 supersav144  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-December 09

Re: Call Stored Procedure

Posted 02 December 2009 - 02:14 AM

View PostPsychoCoder, on 1 Dec, 2009 - 08:35 AM, said:

@karimi: Once again we have a policy here that we show [b]no source code[/url] until the OP shows an effort (which this person did not do). I've had to say this to you before, please dont make me do it a third time :)

@supersav144
[rules][/rules]


right below is the code that i've written to go with the query which doesn't seem to work...I have blanked out the connection string for security reasons:

private void button1_Click(object sender, EventArgs e)
		{
			string source = textBox1.Text;

			string connectionstring = "Data Source=;Persist Security Info=True;User ID=;Password=;Unicode=True";
		
			using (OracleConnection connection = new OracleConnection(connectionstring))
			{
				

				connection.Open();
				OracleCommand comm = new OracleCommand("DRL_PROCEDURE2", connection);
				comm.Parameters.AddWithValue("var_SOURCE_OBJECTID", source);
				comm.Parameters.Add("var_NEW_OBJECTID"); 

				comm.CommandType = CommandType.StoredProcedure;

				OracleDataAdapter da = new OracleDataAdapter(comm);
				DataTable dt = new DataTable();
				da.Fill(dt);

				dataGridView1.DataSource = dt;
				connection.Close();

			}
		}



thankyou
Was This Post Helpful? 0
  • +
  • -

#7 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Call Stored Procedure

Posted 02 December 2009 - 08:25 PM

View Postsupersav144, on 2 Dec, 2009 - 01:14 AM, said:

OracleCommand comm = new OracleCommand("DRL_PROCEDURE2", connection);

You don't specify any parameters on the command to be replaced by the AddParamter method.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1