First of all I did a lot of research on this topic but unfortunately I did not find what works for me. This is my stored procedure
USE [SIM]
GO
Create Proc [dbo].[AddPaymentTracking]
@NPaymentRequest nvarchar(50),
@DatePayment date,
@id int out
AS
INSERT INTO [dbo].[PaymentTracking]
([NPaymentRequest]
,[DatePayment])
VALUES
(@NPaymentRequest,
@DatePayment)
Set @id=@@IDENTITY
and this is my c# class code
public async Task AddPaymentTracking(string NPaymentRequest, DateTime DatePayment)
{
DAL.DataAccessLayer DAL = new DAL.DataAccessLayer();
await Task.Run(() => DAL.Open()).ConfigureAwait(false);
SqlParameter[] param = new SqlParameter[3];
param[0] = new SqlParameter("@NPaymentRequest", SqlDbType.NVarChar, 50)
{
Value = NPaymentRequest
};
param[1] = new SqlParameter("@DatePayment", SqlDbType.Date)
{
Value = DatePayment
};
param[2] = new SqlParameter("@id", SqlDbType.Int);
param[2].Direction = ParameterDirection.Output;
await Task.Run(() => DAL.ExcuteCommande("AddPaymentTracking", param)).ConfigureAwait(false);
DAL.Close();
}
and this is my c# form code
private async void btnSave_Click(object sender, EventArgs e)
{
await supply.AddPaymentTracking(txtNPaymentRequest.Text, Convert.ToDateTime(txtDatePayment.EditValue, CultureInfo.CurrentCulture)).ConfigureAwait(true);
//int output = Get output Parameter
}
How can I do it ?
Thanks in advance
DAL.ExcuteCommande:var outVal = param[2].Value.. Add an out (or ref) parameter to yourAddPaymentTrackingmethod and assign this value to it before returning.btnSave_Click://int output = Get output Parameter