Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my SP and iam try to get the datatable from sp using LINQ but it is only returning 0.
how can i get datatable

ALTER PROCEDURE [dbo].[SP_on_TblClients]
(
	@Action varchar(50),
	@ClientID bigint=0,
	@CFName varchar(50)=null,
	@CMName varchar(50)=null,
	@CLName varchar(50)=null,
	@CMobile varchar(15)=null,
	@CMobile2 varchar(15)=null,
	@CEMail1 varchar(50)=null,
	@CEMail2 varchar(50)=null,
	@SoftwareID bigint=0,
	@CRemarks varchar(MAX)=null,
	@CRemarks1 varchar(MAX)=null,
	@CRequirement varchar(MAX)=null,
	@SelectTp varchar(50)=null,
	@successstatus int out
	
)
 As
 begin transaction
 if @Action ='select'
	begin
		IF @SelectTp='all'
			begin
				Select ROW_NUMBER()  over(ORDER BY CFName) As SrNo, [ClientID],
				[CFName],
				[CMName],
				[CLName],
				[CMobile],
				[CMobile2],
				[CEMail1],
				[CEMail2],
				[SoftwareID],
				[CRemarks],
				[CRemarks1],
				[CRequirement] from [TblClients]
			end
		else
		    begin
				Select ROW_NUMBER()  over(ORDER BY CFName) As SrNo, [ClientID],
				[CFName],
				[CMName],
				[CLName],
				[CMobile],
				[CMobile2],
				[CEMail1],
				[CEMail2],
				[SoftwareID],
				[CRemarks],
				[CRemarks1],
				[CRequirement] from [TblClients] Where ClientID=@ClientID
		    end	
	end
else if @Action ='update'
		begin
			Update [TblClients] set
			CFName =  @CFName,
			CMName =  @CMName,  
			CLName =  @CLName,
			CMobile =  @CMobile,
			CMobile2 = @CMobile2,
			CEMail1 =  @CEMail1,
			CEMail2 =  @CEMail2,
			SoftwareID = @SoftwareID,  
			CRemarks1 =  @CRemarks1,
			CRemarks =  @CRemarks,
			CRequirement =  @CRequirement
			Where ClientID = @ClientID
		end
else if @Action ='delete'
		begin
			Delete FROM [TblClients] 
			Where ClientID = @ClientID
		end
else if @Action ='insert'
	begin
		Insert Into [TblClients] (
							CFName,
							CMName,
							CLName,
							CMobile,
							CMobile2,
							CEMail1,
							CEMail2,
							SoftwareID,
							CRemarks,
							CRemarks1,
		CRequirement) Values (
							@CFName,
							@CMName,
							@CLName,
							@CMobile,
							@CMobile2,
							@CEMail1,
							@CEMail2,
							@SoftwareID,
							@CRemarks,
							@CRemarks1,
							@CRequirement)
							select SCOPE_IDENTITY()
	end
	SELECT @successstatus =@@ERROR;
	if(@successstatus = 0)
		begin
			commit
		end		
	else
		begin
			rollback
		end


GO
Posted
Comments
Malli_S 17-Feb-14 2:28am    
Your last select statement in SP selects the error number which is your current return value of the SP. If you wanna to return the data table, execute the query which returns the required data from the database. For more details please refer to MSDN.

http://msdn.microsoft.com/en-us/library/d7125bke.aspx
srilekhamenon 17-Feb-14 2:48am    
thanks

1 solution

Your SP shows that you have different cases(Select, Insert, Update, Delete) in one SP only.
If you have inputs for select case(@Action ='select'), then only you will get table in output.
In other cases, you will not get table in output.

You logic in
if @Action ='select'
works fine.
 
Share this answer
 
Comments
srilekhamenon 17-Feb-14 3:31am    
but when iam excuting from linq it is returning 0 my code is

int? iRev = 0;
using (DCClientMgtDataContext dc = new DCClientMgtDataContext())
{
dc.SP_on_TblClients("select",
this.ClientID, this.CFName,
this.CMName, this.CLName,
this.CMobile, this.CMobile2,
this.CEMail1, this.CEMail2,
this.SoftwareID, this.CRemarks,
this.CRemarks1, this.CRequirement,
"all", ref iRev);
}
return iRev ?? 0;

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