我在db中有这个存储过程:
ALTER procedure [dbo].[AddUpdateCams]
@CamImage_UID uniqueidentifier = NULL,
@CamImage_Url1 nvarchar(50) = NULL,
@CamImage_Url2 nvarchar(50) = NULL,
@CamImage_StatusID int = 10,
@CamImage_ItemNr nvarchar(50) = NULL,
@CamImage_OrderNr nvarchar(50) = NULL
as
begin
set nocount on;
if @CamImage_UID is null
begin
set @CamImage_UID = NEWID()
insert into dbo.CamImage (CamImage_UID,CamImage_Url1, CamImage_Url2,
CamImage_StatusID, CamImage_CreateDate, CamImage_ItemNr, CamImage_OrderNr)
values (@CamImage_UID, @CamImage_Url1, @CamImage_Url2, @CamImage_StatusID,
GETDATE(), @CamImage_ItemNr, @CamImage_OrderNr)
end
else
begin
update CamImage
set CamImage_StatusID = @CamImage_StatusID
where CamImage_UID = @CamImage_UID
end
select * from CamImage where CamImage_UID = @CamImage_UID
end
我试图通过使用SqlDataAdapter和DataSet来执行此存储过程,但是在执行时,我的DataSet不返回任何内容并且问题似乎不在Store Procedure中,因为如果我通过sql studio执行,它不会遇到任何问题。
public DataSet runSPDataSet(string _storedProcedure)
{
DataSet _dataSet = new DataSet();
if (validateSP(_storedProcedure))
{
SqlConnection _sqlConnection = new SqlConnection(_connectionString);
SqlCommand _sqlCommand = new SqlCommand(_storedProcedure, _sqlConnection);
_sqlCommand.CommandType = CommandType.StoredProcedure;
if(_sqlParameters.Count != 0)
{
foreach (var item in _sqlParameters)
{
_sqlCommand.Parameters.Add(item.ParameterName, item.SqlDbType).Value = item.Value;
}
}
SqlDataAdapter _dataAdapter = new SqlDataAdapter(_sqlCommand);
try
{
_sqlConnection.Open();
_sqlCommand.ExecuteNonQuery();
_dataAdapter.Fill(_dataSet);
return _dataSet;
}
catch (Exception ex)
{
throw ex;
}
finally
{
_sqlConnection.Dispose();
}
}
return null;
}