我想要查询部分属性。因为。要用到的只有两个。。不想用findall,那样。一些多余的也查出来了。
所以就用以方式来查询。结果老是出现。下面错误。数组中至少一个元素不能被转。。急啊。。高手们帮帮忙啊。。    protected void Band()
    {
      
        SimpleQuery query = new SimpleQuery(typeof(Protype),typeof(string),@"select protype.Pcontent,protype.Pico from Protype protype where protype.Id=:end ");
        query.SetParameter("end",21);
        String[] Flist =(string[])Protype.ExecuteQuery(query);
        lblyuanqu.Text = Common.Common.DisLength(Flist[0][0].ToString(), 50);
        Fimg = Flist[0][1].ToString();
    }“/bbrj-07-21”应用程序中的服务器错误。
--------------------------------------------------------------------------------源数组中至少有一个元素无法被向下转换到目标数组类型。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidCastException: 源数组中至少有一个元素无法被向下转换到目标数组类型。源错误: 
行 24:         SimpleQuery query = new SimpleQuery(typeof(Protype),typeof(string),@"select protype.Pcontent,protype.Pico from Protype protype where protype.Id=:end ");
行 25:         query.SetParameter("end",21);
行 26:         String[] Flist =(string[])Protype.ExecuteQuery(query);
行 27:         lblyuanqu.Text = Common.Common.DisLength(Flist[0][0].ToString(), 50);
行 28:         Fimg = Flist[0][1].ToString();
 源文件: d:\大项目区\bbrjr\bbrj-07-21\Bryuanqu.aspx.cs    行: 26 堆栈跟踪: 
[InvalidCastException: 源数组中至少有一个元素无法被向下转换到目标数组类型。]
   System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable) +0
   System.Collections.ArrayList.CopyTo(Array array, Int32 arrayIndex) +50
   Castle.ActiveRecord.Framework.SupportingUtils.BuildArray(Type type, IEnumerable list, Int32 entityIndex, Boolean distinct) +523
   Castle.ActiveRecord.Queries.SimpleQuery.InternalExecute(ISession session) +47
   Castle.ActiveRecord.ActiveRecordBaseQuery.Castle.ActiveRecord.IActiveRecordQuery.Execute(ISession session) +7
   Castle.ActiveRecord.ActiveRecordBase.ExecuteQuery(IActiveRecordQuery query) +78[ActiveRecordException: Could not perform ExecuteQuery for Protype]
   Castle.ActiveRecord.ActiveRecordBase.ExecuteQuery(IActiveRecordQuery query) +192
   Bryuanqu.Band() in d:\大项目区\bbrjr\bbrj-07-21\Bryuanqu.aspx.cs:26
   Bryuanqu.Page_Load(Object sender, EventArgs e) in d:\大项目区\bbrjr\bbrj-07-21\Bryuanqu.aspx.cs:17
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627 

解决方案 »

  1.   

    String[] Flist =(string[])Protype.ExecuteQuery(query);你怎么知道Protype.ExecuteQuery(query) 返回的结果是string[], 
    明显是错误的, 断点看一下返回结果的类型再做下去
      

  2.   

    code=C#]SimpleQuery query = new SimpleQuery(typeof(Protype),typeof(string),@"select protype.Pcontent,protype.Pico from Protype protype where protype.Id=:end ");
            query.SetParameter("end",21);
            String[] Flist =(string[])Protype.ExecuteQuery(query);[[/code]typeof(string)就是指定的返回类型
      

  3.   

    typeof(string) 是指返回的每行内容的类型如果你的SELECT语句只查询一个字段, 那么typeof(string)是正确的. 返回的string[]结果是多条查询记录.但你现在查询的是两个字段, string没法代表两个字段的内容. 
      

  4.   

    如果你想只查询两个字段, 那么就考虑用回原始的ADO.net来操作sql吧.
      

  5.   

    sozdream  谢谢你我明白了马上给分。。