c# - ASP.NET Stored Procedure method not working -


i have method calling stored procedure:

public list<barcodeclass> checktagid(int tagid) {     barcodes = new list<barcodeclass>();     try     {         using (sqlcommand command = new sqlcommand("uspchecktagid", connection))         {             command.commandtype = commandtype.storedprocedure;             sqlparameter parameter = new sqlparameter("@tg", sqldbtype.int)             {                 direction = parameterdirection.input,                 value = tagid             };             command.parameters.add(parameter);             connection.open();             sqldatareader reader = command.executereader();             while (reader.read())             {             }         }     }         {         connection.close();     }          return barcodes; } 

my problem not work. message: error has occurred. know not connection database because if change stored procedures name stored procedure doesnt return error message. have feeling has part:

    

sqlparameter parameter = new sqlparameter("@tg", sqldbtype.int) {     direction = parameterdirection.input,     value = tagid }; 

because passing in int, if use stored procedure nvarchar , pass in string works! there wrong way passing in int parameter?

here stored procedure:

    declare @tg int      declare @l1r nchar(10) -- label1 return variable     declare @l2r nchar(10) -- label2 return variable     declare @l3r nchar(10) -- label3 return variable     declare @l4r nchar(10) -- label4 return variable     declare @ld1r nchar(15) -- ldata1 return variable     declare @ld2r nchar(15) -- ldata2 return variable     declare @ld3r nchar(15) -- ldata3 return variable     declare @ld4r nchar(15) -- ldata4 return variable     set @tg = 10001     exec uspchecktagid @tg, @l1 = @l1r output, @l2 = @l2r output, @l3 = @l3r output, @l4 = @l4r output,  @ld1 = @ld1r output, @ld2 = @ld2r output, @ld3 = @ld3r output, @ld4 = @ld4r output     print @l1r     print @l2r     print @l3r     print @l4r     print @ld1r     print @ld2r     print @ld3r     print @ld4r 

please help! can't debug because database works on server pushing , dont have access server.

the syntax of creating sp in sql server is:

create procedure [schema].[procname]     @param1 int,      @param2 bit begin     -- sp logic     declare @somevar int, -- note variable, not parameter.             @anothervar varchar(10)      -- select, updates, deletes, etc end 

what you've posted proc definition (which incomplete) not have parameter name @tg, rather variable. if correct proc follow above example, using parameters rather variables, should solve immediate problem.

additionally, based on code comments, looks you're attempting use output parameters. need set in sp declaration (just normal parameters) out or output modifier.

it seems want this:

create procedure myspname     @tg int, -- input parameter     @l1r nchar(10) out, -- output parameter -- label1 return variable     @l2r nchar(10) out, -- label2 return variable     @l3r nchar(10) out, -- label3 return variable     @l4r nchar(10) out, -- label4 return variable     @ld1r nchar(15) out, -- ldata1 return variable     @ld2r nchar(15) out, -- ldata2 return variable     @ld3r nchar(15) out, -- ldata3 return variable     @ld4r nchar(15) out -- ldata4 return variable begin     -- sp body end 

to use parameters in c# code use example:

add parameter:

sqlparameter output = new sqlparameter("@l1r", sqldbtype.nvarchar); output.direction = parameterdirection.output; cmd.parameters.add(output); 

read parameter:

string l1r = cmd.parameters["@l1r"].value.tostring(); 

Comments