特定のSQL Serverストアドプロシージャを実行するときに、SqlDataAdapter
がを満たしていないという問題があります。ここDataTableにSqlDataAdapterが埋め込まれていません
は、ストアドプロシージャを実行し、充填DataTable
を返す関数です。
public DataTable getAssetClassifications(int? pLevel)
{
// Create dataTable to hold data
var dt = new DataTable();
// Initialize connection
using (connection = new SqlConnection(connectionString))
using (SqlCommand command = connection.CreateCommand())
using (SqlDataAdapter adapter = new SqlDataAdapter(command))
{
// Open connection
connection.Open();
// Set connection properties
command.CommandText = "BR_Manage_Primary_Classification_GetItemsAssets";
command.CommandType = CommandType.StoredProcedure;
// Add params
command.Parameters.AddWithValue("@pLevel", pLevel);
// Create return value parameter
SqlParameter returnValue = new SqlParameter();
returnValue.Direction = ParameterDirection.ReturnValue;
// Add return value to command
command.Parameters.Add(returnValue);
// Execute command
command.ExecuteNonQuery();
// Fill DataTable
adapter.Fill(dt);
// Get result
var result = returnValue.Value;
Console.WriteLine("Get asset classifications result: " + result.ToString());
if (result.Equals(0))
{
return dt;
}
}
return null;
}
pLevel = null
でこれを実行すると、それが382行のレコードセットを返すべきであるヌルを返します。デバッグから私は 'adapter.fill(dt)'は382を返すが、DataTable 'dt'は満たされていないとわかる。
ストアドプロシージャを次に示します。これは、DAL呼び出す
CREATE PROCEDURE BR_Manage_Primary_Classification_GetItemsAssets
/*
TODO: Allow for subsets based on tree branches
*/
@pLevel AS INT = NULL
AS
BEGIN
/*
Description: Independently returns asset classifications
exec BR_Manage_Primary_Classification_GetItemsAssets
Outputs: None
NOTE: This BR doesn't write, so it doesn't audit but it does error log the call to the DAL.
*/
SET xact_abort, nocount on
DECLARE @StoredProcedureName AS SYSNAME = quotename(object_schema_name(@@procid))+'.'+quotename(object_name(@@procid))
DECLARE @Parameters AS NVARCHAR(1000) = 'Parameters: '
DECLARE @LocalError AS INT
DECLARE @LocalErrorMessage AS NVARCHAR(2048)
DECLARE @NewAuditID AS INT = NULL
BEGIN TRY
BEGIN TRANSACTION
EXEC DAL_Primary_Classification_GetItemsAssets
COMMIT TRANSACTION
-- Return SUCCESS
RETURN 0
END TRY
BEGIN CATCH
-- On fail close any open transactions and write to Error Log
SET @LocalError = @@ERROR
SET @LocalErrorMessage = ERROR_MESSAGE()
IF @@trancount > 0
ROLLBACK TRANSACTION
-- Actual error logging
EXEC DAL_System_LogError null, @StoredProcedureName, @LocalError, @LocalErrorMessage, @Parameters, null, null, null
-- Return Error
RETURN 1
END CATCH
END
:テキストの壁のために申し訳ありません
CREATE PROCEDURE [dbo].[DAL_Primary_Classification_GetItemsAssets]
as
begin
/*
Description: Returns all assets
exec [DAL_Primary_Classification_GetItemsAssets]
exec DAL_Primary_Classification_GetItems 3, 4
Outputs: None
*/
set nocount on;
select c.id as rule_id,
c.[Description] as rule_description,
c.Comment as rule_comment,
l91.id as L91_IDm,
l91.name as L91_Name,
l91.[Description] as L91_Description,
l91.Comment as L91_Comment,
l92.id as L92_ID,
l92.name as L92_Name,
l92.[Description] as L92_Description,
l92.Comment as L92_Comment
from Classifications_Assets as c
left outer join Class_L9_1 as l91 on c.Class_L9_1_ID = l91.ID and l91.Deleted = 0
left outer join Class_L9_2 as l92 on c.Class_L9_2_ID = l92.ID and l92.Deleted = 0
where c.Deleted = 0
end
を、任意の助けをいただければ幸いです!この回答で
デバッガで 'resultValue'の値をチェックしましたか? –
結果値を返す0 ... :( –