Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my stored procedure i want to display idcount in message box in using to sql C# code
SQL
ALTER PROCEDURE [dbo].[Transaction]  
( 
           
            @Patient nvarchar(50),
            @E_TO nvarchar(50),
            @R_type int,
            @User_id uniqueidentifier,
            @ReportType nvarchar(50),
            @Patient_no  int,
            @Patient_ID_NO numeric(18,0),
            @idcount int output
   
) 
AS  
BEGIN  
           
         declare @tempid int
         set @tempid = 0;  
         declare @idcnt int
         select @idcnt =isnull( max(idcount),0) from Transactions where year(R_date)=year(getdate())  
         if (@idcnt =0)  
         set @tempid=1  
         else  
         set @tempid = @idcnt +1  
        
          
          INSERT INTO dbo.Transactions (Patient,E_TO,R_date,R_from,User_id,report_type,Patient_no,Patient_ID_NO,idcount)values (@Patient,@E_TO,getdate(),@R_type,@User_id,@ReportType,@Patient_no,@Patient_ID_NO,@tempid)
return @idcount
   END
Posted
Updated 25-Jun-12 22:55pm
v2

Hi,
I think your stored Procedure is right.
You need to fetch output parameter in your C# Application like.

cnnConnection.Open();
cmdSQLCommand.ExecuteNonQuery();
// Read Values of Output Paramters and Stored into Property
string mErrorMsg ="";
mErrorMsg = (string)(cmdSQLCommand.Parameters["@idcount"].Value);
 
Share this answer
 
v2
how can i fetch my idcount in c# using LINQ???? visit this link please.... i have my code here
LINQ to sql one column is not inserting[^]
 
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