I have a problem with the code below, I keep getting
"Procedure or function 'InsertFile' Expects parameter '@ID', which was not supplied"
I have to do something wrong when returning the id.
ALTER PROCEDURE [dbo].[InsertFile]
@ComputerName varchar(max),
@FilePath varchar(max),
@Owner varchar(100),
@Size int,
@Extension varchar(50),
@CreationDate datetime,
@ModifiedDate datetime,
@AccessedDate datetime,
@ID int output
AS
BEGIN
SET NOCOUNT ON;
IF NOT EXISTS (SELECT * From DC_Files Where computerName = @ComputerName AND FilePath = @FilePath)
BEGIN
INSERT INTO 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
WHERE computerName = @ComputerName AND FilePath = @FilePath
END
SET @ID = SCOPE_IDENTITY()
END
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();