I am calling a stored procedure from my desktop app and that stored procedure returns multiple results.
But when I store the result into a DataTable, only the very 1st results is filled.
Can someone help me out with this.
The stored procedure that I used is:
ALTER PROCEDURE [dbo].[InsertIntoUserLogsAndImageArchive]
@UserName NVARCHAR(50),
@CompUserName NVARCHAR(50),
@CompName NVARCHAR(50),
@DateTime NVARCHAR(50),
@EAN NVARCHAR(50),
@Path NVARCHAR(50),
@FileName NVARCHAR(50),
@BatchId NVARCHAR(50)
AS
BEGIN
DECLARE @ULId NVARCHAR(50), @AId NVARCHAR(50)
INSERT INTO [UserLogs] (UserName, CompUserName, CompName, DateTime) OUTPUT INSERTED.ULId --into @ULId
VALUES (@UserName, @CompUserName, @CompName, @DateTime);
SELECT @ULId = SCOPE_IDENTITY();
INSERT INTO [ImagesArchive] (EAN, Path, FileName, BatchId, ULId)
OUTPUT INSERTED.AId
VALUES (@EAN, @Path, @FileName, @BatchId, @ULId);
SELECT @AId = SCOPE_IDENTITY();
SELECT ULId, AId
FROM ImagesArchive
WHERE AId = @AId;
END
And the code snippet to receive data is:
public DataTable ExecuteQuery2(string storedProcedureName, List<SqlParameter> param)
{
DataTable dt = new DataTable();
using (SqlConnection cn = GetConnection(""))
{
using (SqlCommand cmd = cn.CreateCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = storedProcedureName;
cmd.Parameters.AddRange(param.ToArray());
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
}
}
}
return dt;
}
Executing the stored procedure returns following:
I want to get the very last result in my DataTable instead of the 1st one. Although I have other options but I really want to go with this.
Please help!