首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么在SQL存储过程执行期间空单元格引发错误?

为什么在SQL存储过程执行期间空单元格引发错误?
EN

Stack Overflow用户
提问于 2014-12-01 21:21:28
回答 4查看 1.4K关注 0票数 0
代码语言:javascript
运行
复制
SELECT
    CAST ([content_html] AS XML).query('/root/Physicians/specialty/a') AS [Specialty1]
    , CAST ([content_html] AS XML).query('/root/Physicians/specialty2/a') AS [Specialty2]
    , CAST ([content_html] AS XML).query('/root/Physicians/specialty3/a') AS [Specialty3]
    , CAST ([content_html] AS XML).query('/root/Physicians/specialty4/a') AS [Specialty4]
    , CAST ([content_html] AS XML).query('/root/Physicians/specialty5/a') AS [Specialty5]
    , CAST ([content_html] AS XML).query('/root/Physicians/specialty6/a') AS [Specialty6]
FROM
    [db].[dbo].[content]
WHERE
    [folder_id] = '188'
    AND
    (content_status = 'A')
ORDER BY
    [content_title]

ASP.net中继器(部分):

代码语言:javascript
运行
复制
<asp:Label ID="lblSpec1" runat="server"><%# Eval("Specialty1").ToString() + DisplayMultipleValues(Eval("Specialty2").ToString()) + DisplayMultipleValues(Eval("Specialty3").ToString()) + DisplayMultipleValues(Eval("Specialty4").ToString()) + DisplayMultipleValues(Eval("Specialty5").ToString()) + DisplayMultipleValues(Eval("Specialty6").ToString()) %></asp:Label>

C# (处理多个条目并添加,的代码):

代码语言:javascript
运行
复制
public string DisplayMultipleValues(string strValue)
{
    return (NonBlankValueOf(strValue));
}
public string NonBlankValueOf(string source)
{
    return (string.IsNullOrEmpty(source)) ? "" : ", " + source;
}

当我在SQL中运行查询时,它工作正常(如果列没有值,那么它是一个空单元格),但是通过后面的代码运行它,会给出以下错误:

代码语言:javascript
运行
复制
Server Error in '/' Application.

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Specialty3'.

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.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Specialty3'.

Source Error: 


Line 96:                                     </div>
Line 97:                                     <div class="optionRight">
Line 98:                                         <asp:Label ID="lblSpec1" runat="server"><%# Eval("Specialty1").ToString() + DisplayMultipleValues(Eval("Specialty2").ToString()) + DisplayMultipleValues(Eval("Specialty3").ToString()) + DisplayMultipleValues(Eval("Specialty4").ToString()) + DisplayMultipleValues(Eval("Specialty5").ToString()) + DisplayMultipleValues(Eval("Specialty6").ToString()) %></asp:Label>
Line 99:                                     </div>
Line 100:                                </div>

Source File: c:\er.aspx    Line: 98 

Stack Trace: 


[HttpException (0x80004005): DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Specialty3'.]
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +12523742
   System.Web.UI.DataBinder.Eval(Object container, String[] expressionParts) +142
   ASP.find_provider_aspx.__DataBind__control22(Object sender, EventArgs e) in c:\er.aspx:98
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +304
   System.Web.UI.Control.DataBindChildren() +12746711
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +321
   System.Web.UI.Control.DataBindChildren() +12746711
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +321
   System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +183
   System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +659
   System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +164
   find_provider.Search() in c:\er.aspx.cs:294
   find_provider.Page_Load(Object sender, EventArgs e) in c:\er.aspx.cs:37
   System.Web.UI.Control.LoadRecursive() +71
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3178

解决这个问题的最好办法是什么?

我尝试了以下几点:

代码语言:javascript
运行
复制
<asp:Label ID="lblspec1" runat="server"><%# If(Eval("Specialty1").ToString() Is DBNull.Value, "", Eval("Specialty1").ToString()) + If(Eval("Specialty2").ToString() Is DBNull.Value, "", DisplayOffices(Eval("Specialty2").ToString())) + If(Eval("Specialty3").ToString() Is DBNull.Value, "", DisplayOffices(Eval("Specialty3").ToString())) + If(Eval("Specialty4").ToString() Is DBNull.Value, "", DisplayOffices(Eval("Specialty4").ToString())) + If(Eval("Specialty5").ToString() Is DBNull.Value, "", DisplayOffices(Eval("Specialty5").ToString())) + If(Eval("Specialty6").ToString() Is DBNull.Value, "", DisplayOffices(Eval("Specialty6").ToString())) %></asp:Label>
EN

Stack Overflow用户

回答已采纳

发布于 2014-12-02 05:49:50

您可以将类似的内容添加到页面后面的代码中:

代码语言:javascript
运行
复制
protected object MyEval(string expression)
{
    object o = null;
    try
    {
        o = DataBinder.Eval(this.GetDataItem(), expression);
    }
    catch
    {
        o = System.String.Empty;
    }
    return o;
}

然后用“MyEval”替换所有的渐变:

代码语言:javascript
运行
复制
<asp:Label ID="lblSpec1" runat="server"><%# MyEval("Specialty1").ToString() + DisplayMultiplMyEvalues(MyEval("Specialty2").ToString()) + DisplayMultiplMyEvalues(MyEval("Specialty3").ToString()) + DisplayMultiplMyEvalues(MyEval("Specialty4").ToString()) + DisplayMultiplMyEvalues(MyEval("Specialty5").ToString()) + DisplayMultiplMyEvalues(MyEval("Specialty6").ToString()) %></asp:Label>
票数 1
EN
查看全部 4 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27237555

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档