Saved Procedure Use 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 tried to execute it with visual studio 2010 asp.net.

After learning the code, I found out that I should use

  cmd.CommandType = CommandType.StoredProcedure 

But unfortunately, CommandType.StoredProcedure is not there, it does not work.

Therefore, I used:

 cmd.CommandType = SqlDataSourceCommandType.StoredProcedure; 

But that doesn't work either. He shows me the red line below [How it comes when we enter something invalid]. As a hint, it shows me an error like: CommandType does not exists in current context

My full code is:

 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's my mistake?

Which command should I use to implement the stored procedure?

Please help me.

+4
source share
5 answers

Try it like this:

 System.Data.CommandType.StoredProcedure 

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

+4
source

First use namespace

 using System.Data; 

Then you can use:

 CommandType.StoredProcedure 
+3
source

Need to use like this

 System.Data.CommandType.StoredProcedure 

Also make sure that a reference to System.Data is required.

+2
source

try using the namespace using System.Data;

+2
source

I think you are missing a line of strike

 using System.Data; 

You need to use this name file for "SqlDataSourceCommandType.StoredProcedure".

+1
source

Source: https://habr.com/ru/post/1480419/


All Articles