I am using a WHERE NOT EXISTS
SQL statement to filter away duplicates when doing an INSERT
.
How can I notify my WPF-application user that a duplicate has been skipped?
CodePudding user response:
I ended up using the SQL variable @@ROWCOUNT
.
Added it to my stored procedure:
CREATE PROCEDURE [dbo].[p_procedure_name]
@rowCount int output
AS
BEGIN TRANSACTION
SET NOCOUNT ON
INSERT INTO [dbo].[table_name] (/* column list */)
SELECT /* columns */
FROM [dbo].[another_table_name]
SET @rowCount = @@ROWCOUNT
RETURN
COMMIT TRANSACTION
And then, in my C# code:
SqlParameter param = new();
param.SqlDbType = SqlDbType.Int;
param.Direction = ParameterDirection.Output;
cmd.Parameters.Add(param);
dr = cmd.ExecuteReader();
dr.Close();
int rows = cmd.Parameters["@rowCount"].Value.ToString();