Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
am having one issue.... i write a procedure like below, and need to call it in insert statement...

CREATE PROCEDURE P_NextSequenceNo
AS
SET NOCOUNT ON
DECLARE @iReturn int
BEGIN TRANSACTION
SELECT @iReturn = Sequence FROM dbo.EMPSEQUENCE
UPDATE dbo.EMPSEQUENCE SET Sequence = ( Sequence + 1 )
COMMIT TRANSACTION
SELECT @iReturn
RETURN @iReturn

And after that i have to call that function into below Insert Statement in place of SeqNoKey column.

Insert Into EmpSequence (InvoiceNo, column1, column2, column3)
select 'SeqNoKey ', b.value3, 0, a.value1, c.value4
from table1 a,
join table3 b on a.value1=b.value3
and join table2 c on c.value4 = a.value1
Posted
Updated 1-May-12 23:32pm
v4
Comments
bbirajdar 2-May-12 5:16am    
Oh.. Was it so urgent that you missed to post the question as well. Anyway , there's no urgency from our side
OriginalGriff 2-May-12 5:19am    
Urgency deleted: It may be urgent to you, but it isn't to us. All that your stressing the urgency does is to make us think you have left it too late, and want us to do it for you. This annoys some people, and can slow a response.
Ankur\m/ 2-May-12 5:19am    
Reason for my vote of 1
There is no content in the question. If you say it's urgent, you must show what you have been trying and where you failed.

1 solution

Even though you question is blank: yet there are two question I have to ask.
1 - You wanna know how to write Stored Procedure in Sql Server.
2 - You know the answer for above question but wanna know how to use that stored procedure in C# application.

Most probably its the second case (though you did not mention it, actually you mentioed NOTHING :() ). In that case here can be the solution

C#
public void InsertRecord(int StudentId, string StudentName)
{
  //Sql Connection Object
  SqlConnection conn = new SqlConnection("your connection string");

  //Sql Command Object
  SqlCommand command = new SqlCommand("InsertSpName", conn);
  command.CommandType = CommandType.StoredProcedure;

  //now execute the stored procedure
  command.ExecuteNonQuery();
}


Remember this is just an idea how you would do things. Don't pin point the problems in THIS code :)
 
Share this answer
 
Comments
karthika -chennai 2-May-12 5:35am    
sorry friend,
by mistake the post gets deleted, now i add my question,. pls find it...
thank you...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900