Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

table value functions Expand / Collapse
Author
Message
Posted Wednesday, February 20, 2013 5:09 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, May 07, 2013 12:15 AM
Points: 123, Visits: 502
i am passing table from C# to sql.
on sql this is my code :
CREATE TYPE [dbo].[CampaignIdList] AS TABLE(
[BLMJ] NVARCHAR(50) NOT NULL
)
GO
CREATE PROCEDURE [dbo].[casp_GetExist]
@BLMJ_LIST CampaignIdList READONLY
AS
BEGIN
SET NOCOUNT ON;
Select * from @BLMJ_LIST

END
GO

then i take the code as i see it on the profiler :
declare @p3 dbo.CampaignIdList
insert into @p3 values(N'1247')
insert into @p3 values(N'1261')
insert into @p3 values(N'1277')
insert into @p3 values(N'1279')
insert into @p3 values(N'1289')
select * from @p3 -->> isee that there is data in @p3
execute sp_executesql N'exec casp_GetExist',N'@BLMJ_LIST CampaignIdList READONLY',@p3

when i run the code that i take from the profiler, and i expect for result
from the query : Select * from @BLMJ_LIST
i get no rows as result.
any idea why?
Post #1422026
Posted Wednesday, February 20, 2013 6:11 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 4:54 PM
Points: 1,333, Visits: 4,015
Because you are declaring a parameter for the sp_executesql to use, but not actually using it in the query to execute...

You can either change the last line to this:

execute sp_executesql N'exec casp_GetExist @BLMJ_LIST',N'@BLMJ_LIST CampaignIdList READONLY',@p3;

or this

exec casp_GetExist @BLMJ_LIST=@p3;



MM




Post #1422048
Posted Wednesday, February 20, 2013 6:12 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 4:54 PM
Points: 1,333, Visits: 4,015
Maybe what you really need to do is post the C# code as that seems to be calling wrong...

MM




Post #1422050
Posted Wednesday, February 20, 2013 6:33 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, May 07, 2013 12:15 AM
Points: 123, Visits: 502
fixed the C# code :
SqlCommand cmd = new SqlCommand("casp_GetExist", cnt);
SqlParameter parameter = new SqlParameter();
cmd.CommandType = CommandType.StoredProcedure;
//The parameter for the SP must be of SqlDbType.Structured
parameter.ParameterName = "@BLMJ_LIST";
parameter.TypeName = "CampaignIdList";
parameter.SqlDbType = System.Data.SqlDbType.Structured;
parameter.Value = dataTable;
cmd.Parameters.Add(parameter);
SqlDataReader sqlDR = cmd.ExecuteReader();

but dont get recordset on :sqlDR
Post #1422056
Posted Wednesday, February 20, 2013 11:55 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 4:54 PM
Points: 1,333, Visits: 4,015
have you captured a trace of that new C# code running?

MM




Post #1422234
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse