某列不屬於表,但是列存在


遇到個棘手的問題,在功能中數據層有個方法是返回一個泛型的方法,發布后在IIS中測試,調用10多次都沒有問題,過后就出現這個問題,感覺極為不穩定,然后這個方法一直過不去,要重啟IIS才行,而在VS工具中測試從來不報錯,報錯信息如下: 
異常詳細信息: System.ArgumentException: 列“Props_TypeName”不屬於表 Table。

SQL語句中Props_TypeName,Pi_SmallImg字段都是動態構建的,本身不屬於Idol_PropsPurchases這個表,我以前試過用SqlDataReader來讀取也報類似錯誤.所以 
改為DataTable來操作。 

 

 

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;
        }

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM