遇到个棘手的问题,在功能中数据层有个方法是返回一个泛型的方法,发布后在IIS中测试,调用10多次都没有问题,过后就出现这个问题,感觉极为不稳定,然后这个方法一直过不去,要重启IIS才行,而在VS工具中测试从来不报错,报错信息如下:
异常详细信息: System.ArgumentException: 列“Props_TypeName”不属于表 Table。
我把这个方法贴出来。 public static List<Idol_PropsPurchases> GetPropsBagInfo(int BagId, int Idol_Id)
{
List<Idol_PropsPurchases> Lipp = new List<Idol_PropsPurchases>();
string Sql = "select (select dbo.Props_GetParentName(Pt_Id) from Props_Info where Pi_Id = Ipp.Pi_Id) as Props_TypeName,(select Pi_SmallImg from Props_Info where Pi_Id = Ipp.Pi_Id) as Pi_SmallImg,* from Idol_PropsPurchases Ipp where datediff(s,convert(varchar(20),getdate(),120),Ipp_EndTime)>0 and Ipp_IsUse = 0 and Bag_Id="+BagId+" and Idol_Id="+Idol_Id+"";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MemberDBCS"].ConnectionString);
con.Open();
SqlDataAdapter Sda = new SqlDataAdapter(Sql, con);
DataSet Ds = new DataSet();//;SqlHelper.GetDataTable(Sql)
Sda.Fill(Ds);
DataTable Dt = Ds.Tables[0];
con.Close();
if (Dt.Rows.Count != 0)
{
foreach (DataRow Row in Dt.Rows)
{
Idol_PropsPurchases Ipp = new Idol_PropsPurchases();
Ipp.Props_TypeName = Row["Props_TypeName"].ToString();
Ipp.Pi_SmallImg = Row["Pi_SmallImg"].ToString();
Ipp.Pi_Id = int.Parse(Row["Pi_Id"].ToString());
Ipp.Ipp_AccumulationCount = int.Parse(Row["Ipp_AccumulationCount"].ToString());
Ipp.Ipp_PositionNum = int.Parse(Row["Ipp_PositionNum"].ToString());
Ipp.Ipp_IsProps = bool.Parse(Row["Ipp_IsProps"].ToString());
Lipp.Add(Ipp);
}
}
return Lipp;
}
SQL语句中Props_TypeName,Pi_SmallImg字段都是动态构建的,本身不属于Idol_PropsPurchases这个表,我以前试过用SqlDataReader来读取也报类似错误.所以
改为DataTable来操作。
异常详细信息: System.ArgumentException: 列“Props_TypeName”不属于表 Table。
我把这个方法贴出来。 public static List<Idol_PropsPurchases> GetPropsBagInfo(int BagId, int Idol_Id)
{
List<Idol_PropsPurchases> Lipp = new List<Idol_PropsPurchases>();
string Sql = "select (select dbo.Props_GetParentName(Pt_Id) from Props_Info where Pi_Id = Ipp.Pi_Id) as Props_TypeName,(select Pi_SmallImg from Props_Info where Pi_Id = Ipp.Pi_Id) as Pi_SmallImg,* from Idol_PropsPurchases Ipp where datediff(s,convert(varchar(20),getdate(),120),Ipp_EndTime)>0 and Ipp_IsUse = 0 and Bag_Id="+BagId+" and Idol_Id="+Idol_Id+"";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MemberDBCS"].ConnectionString);
con.Open();
SqlDataAdapter Sda = new SqlDataAdapter(Sql, con);
DataSet Ds = new DataSet();//;SqlHelper.GetDataTable(Sql)
Sda.Fill(Ds);
DataTable Dt = Ds.Tables[0];
con.Close();
if (Dt.Rows.Count != 0)
{
foreach (DataRow Row in Dt.Rows)
{
Idol_PropsPurchases Ipp = new Idol_PropsPurchases();
Ipp.Props_TypeName = Row["Props_TypeName"].ToString();
Ipp.Pi_SmallImg = Row["Pi_SmallImg"].ToString();
Ipp.Pi_Id = int.Parse(Row["Pi_Id"].ToString());
Ipp.Ipp_AccumulationCount = int.Parse(Row["Ipp_AccumulationCount"].ToString());
Ipp.Ipp_PositionNum = int.Parse(Row["Ipp_PositionNum"].ToString());
Ipp.Ipp_IsProps = bool.Parse(Row["Ipp_IsProps"].ToString());
Lipp.Add(Ipp);
}
}
return Lipp;
}
SQL语句中Props_TypeName,Pi_SmallImg字段都是动态构建的,本身不属于Idol_PropsPurchases这个表,我以前试过用SqlDataReader来读取也报类似错误.所以
改为DataTable来操作。
解决方案 »
- 多表修改 我不懂
- 关于"最新上传"的功能设计.
- 生成静态页的问题~~~
- asp.net上传漏洞
- 为什么不能建立ASP.NET文件?
- 如何利用MVC和NHIBERNATE与spring.net组成一个应用架构?需要DAO吗
- 在c#程序中 该如何获得网上站点的html代码?
- 如何通过SQL语句保存IMAGE类型的数据
- 二维数组与数据库的问题
- 我在datalist中加入一个项模板,可以是<asp:HyperLink>或者<asp:LinkButton>,我现在想点击探出一个新的窗口,同时还要加上来自数据库的参
- ASP.net页面怎样转换为PDF文件保存在客户端?
- 如何隐藏fileupload的文本框
//应该是没有什么问题
//加try catch finally 试试public static List<Idol_PropsPurchases> GetPropsBagInfo(int BagId, int Idol_Id)
{
try{
List<Idol_PropsPurchases> Lipp = new List<Idol_PropsPurchases>();
string Sql = "select (select dbo.Props_GetParentName(Pt_Id) from Props_Info where Pi_Id = Ipp.Pi_Id) as Props_TypeName,(select Pi_SmallImg from Props_Info where Pi_Id = Ipp.Pi_Id) as Pi_SmallImg,* from Idol_PropsPurchases Ipp where datediff(s,convert(varchar(20),getdate(),120),Ipp_EndTime)>0 and Ipp_IsUse = 0 and Bag_Id="+BagId+" and Idol_Id="+Idol_Id+"";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MemberDBCS"].ConnectionString);
con.Open();
SqlDataAdapter Sda = new SqlDataAdapter(Sql, con);
DataSet Ds = new DataSet();//;SqlHelper.GetDataTable(Sql)
Sda.Fill(Ds);
DataTable Dt = Ds.Tables[0]; if (Dt.Rows.Count != 0)
{
foreach (DataRow Row in Dt.Rows)
{
Idol_PropsPurchases Ipp = new Idol_PropsPurchases();
Ipp.Props_TypeName = Row["Props_TypeName"].ToString();
Ipp.Pi_SmallImg = Row["Pi_SmallImg"].ToString();
Ipp.Pi_Id = int.Parse(Row["Pi_Id"].ToString());
Ipp.Ipp_AccumulationCount = int.Parse(Row["Ipp_AccumulationCount"].ToString());
Ipp.Ipp_PositionNum = int.Parse(Row["Ipp_PositionNum"].ToString());
Ipp.Ipp_IsProps = bool.Parse(Row["Ipp_IsProps"].ToString());
Lipp.Add(Ipp);
}
}
return Lipp;
}
catch(Exception ex)
{
throw new Exception(ex.Message.Tostring());
}
finally
{
con.Close();
}
}
---------------------------------------set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go--获取指定Pt_Id对应的中类,大类名称
ALTER FUNCTION [dbo].[Props_GetParentName]
(
@Pt_Id int --物品类型Id
)
RETURNS varchar(100)
AS
BEGIN
--结果变量
declare @R varchar(100)
set @R = (select Pt_Name from Props_Type where Pt_Id = (select (select Pt_ParentId from Props_Type where Pt_Id = pt.Pt_ParentId) as Pt_Id from Props_Type pt where Pt_Id=@Pt_Id));
if charindex('衣服\',@R)>0
begin
set @R = (select (select Pt_Name from Props_Type where Pt_Id = Pt.Pt_ParentId) from Props_Type Pt where Pt_Id = @Pt_Id);
end
if charindex('鞋子',@R)>0
begin
set @R = '装饰品';
end
if charindex('头',@R)>0
begin
set @R = (select Pt_Name from Props_Type where Pt_Id = @Pt_Id);
end
return @R;
END
--获取指定Pt_Id对应的中类,大类名称
--做了点修改!
ALTER FUNCTION [dbo].[Props_GetParentName]
(
@Pt_Id int --物品类型Id
)
RETURNS varchar(100)
AS
BEGIN
--结果变量
declare @R varchar(100)
set @R = '' --先赋值
set @R = (select Pt_Name from Props_Type where Pt_Id = (select (select Pt_ParentId from Props_Type where Pt_Id = pt.Pt_ParentId) as Pt_Id from Props_Type pt where Pt_Id=@Pt_Id));
if charindex('衣服\',@R)>0
begin
select @R = (select Pt_Name from Props_Type where Pt_Id = Pt.Pt_ParentId) from Props_Type Pt where Pt_Id = @Pt_Id
end
if charindex('鞋子',@R)>0
begin
set @R = '装饰品';
end
if charindex('头',@R)>0
begin
select @R =Pt_Name from Props_Type where Pt_Id = @Pt_Id
end
return @R;
END
charindex('衣服\',@R)>0--这要加 \ 么?
@yzoneyzone:这个问题怎么解决的啊?我也遇到了