hi
when I run it below error happen
Invalid attempt to read when no data is present.
below is SP
ALTER procedure [dbo].[GetCustomersPageWiseS1]
@PageIndex INT = 1
,@PageSize INT = 5
,@RecordCount INT OUTPUT
,@BehCode nvarchar(10)
,@Classification nvarchar(30)
AS
BEGIN
SET NOCOUNT ON;
SELECT ROW_NUMBER() OVER
(
ORDER BY [Date] desc
)AS RowNumber
,[ID]
,[Name]
,[Image]
,[Date]
,[Model]
,[H_name1]
INTO #Results
FROM [House_p]
WHERE Classification=@Classification and BehCode=@BehCode
SELECT @RecordCount = COUNT(*)
FROM #Results
SELECT * FROM #Results
WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
DROP TABLE #Results
END
and code
private void GetCustomersPageWiseP1(int pageIndex, string linkButtonText)
{
using (SqlConnection conn = General.GetConnection())
{
using (SqlCommand cmd = General.GetCommand("GetCustomersPageWiseS1", conn))
{
string val = ViewState["LinkButtonValue"].ToString();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@behcode", Server.UrlDecode(Request.QueryString["BehCode"]));
cmd.Parameters.AddWithValue("@PageIndex", pageIndex);
cmd.Parameters.AddWithValue("@PageSize", PageSize);
cmd.Parameters.Add("@RecordCount", SqlDbType.Int, 4);
cmd.Parameters.AddWithValue("@classification", ViewState["LinkButtonValue"].ToString());
cmd.Parameters["@RecordCount"].Direction = ParameterDirection.Output;
conn.Open();
SqlDataReader idr = cmd.ExecuteReader();
if (idr.HasRows)
{
DDLP.DataSource = idr;
DDLP.DataBind();
if (idr["H_name1"].ToString() == "خدماتی و رفاهی")
{
imgpro.Visible = false;
}
else
{
imgpro.Visible = true;
}
lblproduct.Visible = true;
}
else
{
DDLP.Visible = false;
Imgapro.ImageUrl = "~/image/imgpro.png";
Imgservice.ImageUrl = "~/image/imgpro1.png";
}
idr.Close();
this.PopulatePagerPL(Convert.ToInt32(cmd.Parameters["@RecordCount"].Value), pageIndex);
}
}
}
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Invalid attempt to read when no data is present.
Source Error:
Line 517: DDLP.DataSource = idr;
Line 518: DDLP.DataBind();
Line 519: if (idr["H_name1"].ToString() == "خدماتی و رفاهی")
Line 520: {
Line 521:
|
Best Regarda
Neda