Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stored Procedure usage in ASP.NET

I am using StoredProcedure in sqlserver 2005.

Stored Procedure:

create proc useGetASP @PartyCode nvarchar(50)
as
select * 
from partyRegister 
where PartyCode=@PartyCode
Go

I was trying to execute it with asp.net visual studio 2010.

By researching for code i came to know i should use

 cmd.CommandType = CommandType.StoredProcedure

But unfortunatly CommandType.StoredProcedure is not there , its not working.

Hence i used:

cmd.CommandType = SqlDataSourceCommandType.StoredProcedure;

But this is also not working. It shows me red line below it [As comes when we type something invalid]. As a tooltip it shows me error as: CommandType does not exists in current context

My Full Code:

con.Open();
cmd = new SqlCommand("useGetASP",con);
//cmd.CommandType =CommandType./*Not Working*/
cmd.CommandType = SqlDataSourceCommandType.StoredProcedure;/*Also Not Working*/
cmd.Parameters.AddWithValue("@PartyCode","0L036");

What is my mistake?

What command should i use for implementing stored procedure?

Please Help Me.

like image 335
Freelancer Avatar asked Dec 15 '22 10:12

Freelancer


2 Answers

Try like this:

System.Data.CommandType.StoredProcedure

Source: http://msdn.microsoft.com/en-us/library/system.data.commandtype.aspx

like image 77
Amit Singh Avatar answered Dec 26 '22 13:12

Amit Singh


First use this namespace

using System.Data;

Then you should be able to use:

CommandType.StoredProcedure
like image 30
Praveen Nambiar Avatar answered Dec 26 '22 13:12

Praveen Nambiar