[英]Getting blank records on Excel sheet when binding it using stored procedure
This is my stored procedure这是我的存储过程
CREATE OR ALTER PROCEDURE [dbo].[sp_TADashboardVoid]
@PartnerId INT,
@UserId BIGINT,
@TAType INT = 0,
@Borough INT = 0,
@LandlordId INT = 0,
@AllocationStartDate DATE = NULL,
@AllocationEndDate DATE = NULL,
@PropertyRef VARCHAR(100) = NULL,
@PropertyType INT = 0,
@PropertyId VARCHAR(100) = NULL,
@PropertyAddress VARCHAR(200) = NULL,
-- @LandlordProperty VARCHAR(100) = NULL
@PropertyStatusId INT = NULL,
@HouseholdId VARCHAR(10) = NULL,
@ReferenceID VARCHAR(50) = NULL,
@VoidStartDate DATE = NULL,
@VoidEndDate DATE = NULL
AS
BEGIN
DECLARE @demotest TABLE (
PropertyID NVARCHAR(MAX)
,App_id INT
,Rent DECIMAL(18, 2)
,RoomId INT
,CreatedDate Date
,StartDate Date
,EndDate Date
,VoidStartDate DATE
,VoidEndDate DATE
--,VoidLoss NVARCHAR(MAX)
)
insert into @demotest
select PropertyId,App_Id,Rent,RoomId,CreatedDate,StartDate,EndDate,EndDate+1 as VoidStartDate,
LEAD(StartDate) OVER (Partition BY PropertyId ORDER by Propertyid) As VoidEndDate
from tbl_AssignAppToProperty
SELECT ROW_NUMBER() OVER (
--ORDER BY A.Reference_id DESC
ORDER BY dt.PropertyId
) AS RowNumber
, app.Reference_ID as ApplicationRef
, A.Reference_ID as PropertyRefId
, A.ID as PropertyID
,vtp.TypeofProperty
,vPN.PropertyName AS PropertyName
,c.title AS Landlord
,P.FirstName
,P.LastName
,Ho.HouseholdLoginId AS HouseholdId
,vrt.RentType as RentFrequency
,dt.Rent
,A.Apptype
,A.FormId --added due to error
, A.session_guid
,CASE
WHEN
app.Reference_ID IS NULL Then A.DateOfSubmission
ELSE dt.VoidStartDate
END AS VoidStartDate
,Case
WHEN
dt.VoidEndDate is NULL Then getdate()
Else dt.VoidEndDate
END AS VoidEndDate
,datediff(ww,dt.VoidStartDate,dt.VoidEndDate) * dt.Rent AS VoidLoss
from tbl_Application A
INNER JOIN tbl_Form F ON F.id = A.FormId
left join @demotest dt on dt.PropertyId = A.ID
left join tbl_Application APP on dt.App_Id = APP.ID
Left JOIN tbl_household HO ON HO.Household_ID = APP.Household_Id
left JOIN v_TypeOfProperty vTP ON vTP.App_Id = A.ID
INNER JOIN v_PropertyName vPN ON A.ID = vPN.App_Id --record dropped from 78 to 57 to display only properties with name
--INNER JOIN tbl_ApplicationSubPortal ASS ON A.ID = ASS.AppID
INNER JOIN v_PropertyAddress vPA ON A.Session_Guid = vPA.MapGuid
LEFT JOIN tbl_applicationlandlord AL ON AL.AppId = A.id
LEFT JOIN tbl_choice c ON C.id = AL.LandlordId
--LEFT JOIN v_PropertyType vPT ON vPT.App_Id = A.ID
LEFT JOIN v_Person P ON P.AppId = dt.App_Id
AND P.HouseholdType = 'M'
LEFT JOIN v_RentType VRT on VRT.APP_ID = A.ID
where A.AppType='pro' --and A.Formid=803
AND F.PartnerId = @PartnerId
AND (
(@TAType = 0)
OR (vTP.TypeOfPropertyId = @TAType)
)
AND (
@PropertyRef IS NULL
OR A.Reference_ID LIKE '%' + @PropertyRef + '%'
)
AND (
@PropertyStatusId IS NULL
OR (A.App_status = @PropertyStatusId)
)
AND (
@PropertyId IS NULL
OR A.Reference_ID LIKE '%' + @PropertyId + '%'
)
AND (
@PropertyAddress IS NULL
OR ((isnull(vPA.FlatNo, '') + ' ' + isnull(vPA.BuildingName, '') + ' ' + isnull(vPA.StreetName, '') + ' ' + isnull(vPA.TownCity, '') + ' ' + isnull(vPA.County, '') + ' ' + isnull(vPA.PostCode, '')) LIKE '%' + @PropertyAddress + '%')
)
AND (
@HouseholdId IS NULL
OR HO.HouseholdLoginId LIKE '%' + @HouseholdId + '%'
)
AND (
@ReferenceID IS NULL
OR APP.Reference_ID LIKE '%' + @ReferenceID + '%'
)
AND (
(
CONVERT(DATE, @VoidStartDate, 103) IS NULL
OR CONVERT(DATE, @VoidEndDate, 103) IS NULL
)
OR (
(
CONVERT(DATE, dt.VoidStartDate, 103) BETWEEN CONVERT(DATE,@VoidStartDate, 103)
AND CONVERT(DATE, @VoidEndDate, 103)
)
AND (
CONVERT(DATE, dt.VoidEndDate, 103) BETWEEN CONVERT(DATE, @VoidStartDate, 103)
AND CONVERT(DATE, @VoidEndDate, 103)
)
)
)
END
This is my BindVoidData
method这是我的
BindVoidData
方法
public System.Data.DataSet BindVoidData(int partnerId, long userId, string taType, string Borough, string landlord, string propertyRef, string propertyType, string propertyAddress , string propertyStatus)
{
SqlCommand sqlCommand = new SqlCommand();
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
DataSet dataTable = new DataSet();
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["HousingRegister"].ConnectionString);
try
{
sqlCommand = new SqlCommand("sp_TADashboardVoid", connection);
sqlCommand.Parameters.Add(new SqlParameter("@PartnerId", partnerId));
sqlCommand.Parameters.Add(new SqlParameter("@UserId", userId));
sqlCommand.Parameters.Add(new SqlParameter("@TAType", taType));
sqlCommand.Parameters.Add(new SqlParameter("@Borough", Borough));
sqlCommand.Parameters.Add(new SqlParameter("@LandlordId", landlord));
sqlCommand.Parameters.Add(new SqlParameter("@PropertyId", propertyRef));
sqlCommand.Parameters.Add(new SqlParameter("@PropertyType", propertyType));
sqlCommand.Parameters.Add(new SqlParameter("@PropertyAddress", propertyAddress));
sqlCommand.Parameters.Add(new SqlParameter("@PropertyStatusId", propertyStatus));
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlDataAdapter.SelectCommand = sqlCommand;
sqlDataAdapter.Fill(dataTable);
}
catch (Exception ex)
{
throw ex;
}
finally
{
sqlCommand.Dispose();
connection.Close();
}
return dataTable;
}
The problem that I am facing is that the datatable is not returning me any rows due to which there are no records on Excel sheet, but when I tested the stored procedure using exec
on SQL Server, it is returning around 200 rows.我面临的问题是数据表没有返回任何行,因为 Excel 工作表上没有记录,但是当我在 SQL Server 上使用
exec
测试存储过程时,它返回了大约 200 行。
Can anyone please help me out on this as I am not sure how to proceed.任何人都可以帮我解决这个问题,因为我不确定如何进行。
Here is the code try this out , I Just edited it into my style of code
这是代码试试这个,我只是把它编辑成我的代码风格
public DataSet BindVoidData(int partnerId, long userId, string taType, string Borough, string landlord, string propertyRef, string propertyType, string propertyAddress, string propertyStatus)
{
SqlDataAdapter da = new SqlDataAdapter();
DataSet Ds = new DataSet();
try
{
var constring = System.Configuration.ConfigurationManager.ConnectionStrings["HousingRegister"].ConnectionString;
using (SqlConnection con = new SqlConnection(constring))
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
using (SqlCommand cmd = new SqlCommand("sp_TADashboardVoid", con))
{
cmd.CommandType = CommandType.StoredProcedure;
//Add the DataType Based on Your StoredProcedure
cmd.Parameters.Add("@PartnerId", SqlDbType.Int, 20);
//After Adding All Data Type Define Value
cmd.Parameters["@PartnerId"].Value = partnerId;
da = new SqlDataAdapter(cmd);
da.Fill(Ds);
cmd.Dispose();
}
con.Close();
}
//Return Data Set
return Ds;
}
catch (Exception ex)
{
throw ex;
}
}
Here is the SQL Server Data Types and Their .NET Framework Equivalents for Add DataType in SqlCommand Link
这是在SqlCommand 链接中添加数据类型的 SQL Server 数据类型及其 .NET Framework 等效项
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.