i want to insert the data to a table and i want to return scope_identity() and value of inserted voucherNumber or ( UpdatedVoucherNo ) .. i got the query but i want to know how can i implement it on Code (c# code ) .. i cant use execute scalar because it only return a single value
right ??
so i want to insert and i need to return a row to code HOW ??? pls help me...
below is my query.. it is working correctly but i want to know to to use it in code !!!!!
@ledgerId numeric(18,0) ,
@voucherNo varchar(MAX) ,
@invoiceNo varchar(MAX) ,
@date datetime ,
@month datetime ,
@totalAmount decimal(18,5) ,
@narration varchar(MAX) ,
@extra1 varchar(MAX) ,
@extra2 varchar(MAX) ,
@suffixPrefixId numeric(18,0) ,
@voucherTypeId numeric(18,0)
AS
DECLARE @UpdatedVoucherNo DECIMAL(18,0)
SET @UpdatedVoucherNo = (SELECT ISNULL( MAX(CAST (voucherNo AS NUMERIC(18,0))),0) + 1
FROM tbl_SalaryVoucherMaster
WHERE voucherTypeId=@voucherTypeId)
IF (@UpdatedVoucherNo = @voucherNo )
INSERT INTO tbl_SalaryVoucherMaster
(
ledgerId,
voucherNo,
invoiceNo,
date,
month,
totalAmount,
narration,
extraDate,
extra1,
extra2,
suffixPrefixId,
voucherTypeId )
VALUES
(
@ledgerId,
@voucherNo,
@invoiceNo,
@date,
@month,
@totalAmount,
@narration,
getDate(),
@extra1,
@extra2,
@suffixPrefixId,
@voucherTypeId)
SELECT SCOPE_IDENTITY() AS [Identity],0 AS [UpdatedVoucherNo]