C# SQL output code issue -


i having issue code below, keep getting

"procedure or function 'insertfile' expects parameter '@id', not supplied"

i must doing wrong in returning of id.

alter procedure [dbo].[insertfile]  -- add parameters stored procedure here     --@assetid int,     @computername varchar(max),     @filepath varchar(max),     @owner varchar(100),     @size int,     @extension varchar(50),     @creationdate datetime,     @modifieddate datetime,     @accesseddate datetime,     @id int output begin -- set nocount on added prevent result sets -- interfering select statements. set nocount on;  if not exists (select * dc_files computername = @computername , filepath = @filepath) begin        insert dc_files (computername, filepath, owner, size, extension, creationdate, modifieddate, accesseddate)         values (@computername, @filepath, @owner, @size, @extension, @creationdate, @modifieddate, @accesseddate) end else begin     update dc_files     set owner = @owner, size = @size, creationdate = @creationdate, modifieddate = @modifieddate, accesseddate = @accesseddate     computername = @computername , filepath = @filepath end set @id = scope_identity() end 

the c# code:

sqlcommand cmd = new sqlcommand("insertfile",conn); cmd.commandtype = commandtype.storedprocedure;  //cmd.parameters.addwithvalue("@assetid", fileinfo); cmd.parameters.addwithvalue("@computername", environment.machinename); cmd.parameters.addwithvalue("@filepath", filepath); cmd.parameters.addwithvalue("@owner", filesecurity.getowner(typeof(ntaccount)).value); cmd.parameters.addwithvalue("@size", fileinfo.length); cmd.parameters.addwithvalue("@extension", fileinfo.extension); cmd.parameters.addwithvalue("@creationdate", filecreationtime); cmd.parameters.addwithvalue("@modifieddate", filemodifiedtime); cmd.parameters.addwithvalue("@accesseddate", fileaccessedtime); var returnparameter = cmd.parameters.add("@id", sqldbtype.int); cmd.executenonquery(); 

you have set direction output since default direction of parameter input.

      // create parameter direction output        sqlparameter returnparameter = new sqlparameter("@id", sqldbtype.int)        {            direction = parameterdirection.output         };     cmd.parameters.add(returnparameter); 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -