我用SQL语句:
select a.jlbh as jlbh1,b.jskl*100 as jskl1,cast(sum(b.xsje) as decimal(10,2)) as xsje1 from jsd a,lyspjsr b where a.hth=b.hth and a.yearmonth=b.yearmonth and a.jlbh=1006789 group by a.jlbh,b.jskl
在SQL server 2000 的查询分析器中可以正常使用。但是在水晶报表中使用时运行后就报错如下:
“/supp”应用程序中的服务器错误。
--------------------------------------------------------------------------------
未能启用约束。一行或多行中包含违反非空、唯一或外键约束的值。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.ConstraintException: 未能启用约束。一行或多行中包含违反非空、唯一或外键约束的值。
源错误:
只有在调试模式下进行编译时,生成此未处理异常的源代码才会显示出来。若要启用此功能,请执行以下步骤之一,然后请求 URL:
1. 在产生错误的文件的顶部添加一条“Debug=true”指令。例如:
<%@ Page Language="C#" Debug="true" %>
或:
2. 将以下的节添加到应用程序的配置文件中:
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>
请注意,第二个步骤将使给定应用程序中的所有文件在调试模式下进行编译;第一个步骤仅使该特定文件在调试模式下进行编译。
重要事项: 以调试模式运行应用程序一定会产生内存/性能系统开销。在部署到生产方案之前,应确保应用程序调试已禁用。
堆栈跟踪:
[ConstraintException: 未能启用约束。一行或多行中包含违反非空、唯一或外键约束的值。]
System.Data.DataSet.FailedEnableConstraints() +21
System.Data.DataSet.EnableConstraints() +456
System.Data.DataSet.set_EnforceConstraints(Boolean value) +81
System.Data.DataTable.EndLoadData() +127
System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue) +229
System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) +353
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +164
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +287
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
supp_Jsd01.Page_Load(Object sender, EventArgs e) +417
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
~~~~~~~~~~~~~~~~~~~~~~~
.aspx中的代码是:
da = new SqlDataAdapter("select a.jlbh as jlbh1,b.jskl*100 as jskl1,cast(sum(b.xsje) as decimal(10,2)) as xsje1 from jsd a,lyspjsr b where a.hth=b.hth and a.yearmonth=b.yearmonth and a.jlbh='" + jlbhR + "'group by a.jlbh,jskl", con);
da.Fill(ds1, "DataTable32");
//jlbh这里我是用别的页面传的一个动态值。
请各位高手多多帮忙,多谢了!