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: Wednesday, April 16, 2014 5:46 AM
Points: 123, Visits: 513
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


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 12:42 PM
Points: 1,787, Visits: 5,696
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


  • MMGrid Addin
  • MMNose Addin


  • Forum Etiquette: How to post Reporting Services problems
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • How to Post Performance Problems - by Gail Shaw

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


    SSCommitted

    SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

    Group: General Forum Members
    Last Login: Yesterday @ 12:42 PM
    Points: 1,787, Visits: 5,696
    Maybe what you really need to do is post the C# code as that seems to be calling wrong...

    MM


  • MMGrid Addin
  • MMNose Addin


  • Forum Etiquette: How to post Reporting Services problems
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • How to Post Performance Problems - by Gail Shaw

  • 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: Wednesday, April 16, 2014 5:46 AM
    Points: 123, Visits: 513
    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


    SSCommitted

    SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

    Group: General Forum Members
    Last Login: Yesterday @ 12:42 PM
    Points: 1,787, Visits: 5,696
    have you captured a trace of that new C# code running?

    MM


  • MMGrid Addin
  • MMNose Addin


  • Forum Etiquette: How to post Reporting Services problems
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • How to Post Performance Problems - by Gail Shaw

  • Post #1422234
    « Prev Topic | Next Topic »

    Add to briefcase

    Permissions Expand / Collapse