hi
below is my 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;
ImgserviceM.Visible = true;
}
else
{
imgpro.Visible = true;
ImgserviceM.Visible = false;
}
lblproduct.Visible = true;
}
else
{
DDLP.Visible = false;
}
idr.Close();
this.PopulatePagerPL(Convert.ToInt32(cmd.Parameters["@RecordCount"].Value), pageIndex);
}
}
}
when I run page this error happen
H_name1
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.IndexOutOfRangeException: H_name1
Source Error:
Line 517: DDLP.DataSource = idr;
Line 518: DDLP.DataBind();
Line 519: if (idr["H_name1"].ToString() == "خدماتی و رفاهی")
Line 520: {
Line 521: imgpro.Visible = false;
|
and SP
USE [behtop]
GO
/****** Object: StoredProcedure [dbo].[GetCustomersPageWise1] Script Date: 11/02/2014 08:41:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[GetCustomersPageWise1]
@H_name nvarchar(50)
,@subset nvarchar(30)
,@PageIndex INT = 1
,@PageSize INT = 5
,@RecordCount INT OUTPUT
,@Region nvarchar(10)
,@district nvarchar(20)
,@City nvarchar(30)
,@shoppingcenter nvarchar(30)
,@labeltext nvarchar(30) OUTPUT
,@labeltext1 nvarchar(30) OUTPUT
,@Id int
AS
BEGIN
SET NOCOUNT ON;
SELECT ROW_NUMBER() OVER
(
ORDER BY [House_p].[Date] desc
)AS RowNumber
,[House_p].[ID]
,[House_p].[Name]
,[House_p].[Image]
,[House_p].[Date]
,[House_p].[H_name1]
,House_Info.Name as NameI
,[House_p].[Model]
,SUBSTRING(House_p.[Description],0,110)+'...' As Description
,(House_info.Code+'-'+House_info.Tell) as tellF
,House_Info.BehCode as Behcode
INTO #Results
FROM [House_p]
JOIN [HOuse_info] ON [House_p].[BehCode] = [HOuse_info].[BehCode]
WHERE ([House_p].H_name=@H_name or [House_p].subset=@subset) and ([HOuse_info].Region = @Region or @Region='همه') and ([House_Info].District=@District or @District='همه') and ([House_Info].ShoppingCenter=@shoppingcenter or @shoppingcenter=N'کلیه اصناف در سطح شهر')
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
SELECT @labelText=(SELECT H_name FROM TradeClass WHERE ID=@Id)
SELECT @labelText1=(SELECT Subset FROM Subset_menu WHERE Subset=@Subset)
END
why this happen?
Best Regards
Neda