Click here to Skip to main content
15,899,475 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
how to create this storeprocedure in microsoft sql  database  from C# , i dont want to use sql managment studio 

CREATE PROCEDURE [dbo].[SP]
@PreCode varchar(2),
@InvNo int OUTPUT

AS

declare @Count int

BEGIN

	set @Count= (select count(InvNo1)  from  tblInvoiceNo )
	IF @Count = 0
	BEGIN
	insert into tblInvoiceNo (InvNo1,InvNo2) values (0,0)
	END



SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
BEGIN TRANSACTION
--WAITFOR DELAY '000:00:30'



			IF @PreCode <> 99
			BEGIN

				set @InvNo= (select InvNo1  from  tblInvoiceNo where InvNo1 like ''+@PreCode+'%')
				IF  @InvNo IS NULL
				BEGIN
				Update tblInvoiceNo set InvNo1 = @PreCode+'000001'
				set @InvNo = @PreCode+'000001'
				END
				ELSE
				BEGIN
				set @InvNo= (select InvNo1  from  tblInvoiceNo where InvNo1 like ''+@PreCode+'%')+1
				Update tblInvoiceNo set InvNo1 = @InvNo
				END

			END
		    
			
			ELSE

			BEGIN
			
			    set @InvNo= (select InvNo2  from  tblInvoiceNo where InvNo2 like ''+@PreCode+'%')
				IF  @InvNo IS NULL
				BEGIN
				Update tblInvoiceNo set InvNo2 = @PreCode+'000001'
				set @InvNo = @PreCode+'000001'
				END
				ELSE
				BEGIN
				set @InvNo= (select InvNo2  from  tblInvoiceNo where InvNo2 like ''+@PreCode+'%')+1
				Update tblInvoiceNo set InvNo2 = @InvNo
				END

            END
			


COMMIT TRANSACTION




END
Posted
Updated 30-Dec-15 1:32am
v3
Comments
Kornfeld Eliyahu Peter 29-Dec-15 2:54am    
Do you mean true SP or CLRI code?
baketharlay 1-Jan-16 7:07am    
CLRI code

1 solution

As you correctly tagged your question, use ADO.NET. :-)

This is the key:
C#
mySqlCommand.CommandType = CommandType.StoredProcedure;

See also: Lesson 07[^].

—SA
 
Share this answer
 

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