我现在用的方法就是:
ls_sql="select * from t_gongwen_liucheng where gwid=1"
......
my_da.Fill(my_ds,"gw_liucheng");
ls_sql="select * from t_gongwen_liucheng_person where gwid=1";
......
my_da.Fill(my_ds,"gw_liucheng_person");
ls_sql="select p_person.name "+
" from GONGWEN_LIUCHENG_PERSON,GongWen_liucheng,p_person "+
" where GongWen_liucheng.GWID=GONGWEN_LIUCHENG_PERSON.GWID "+
"and GongWen_liucheng.bzid=GONGWEN_LIUCHENG_PERSON.bzid "+
"and GongWen_liucheng.GWID=1 "+
"and p_person.pid=gongwen_liucheng_person.pid";
......
my_da.Fill(my_ds,"p_person");
运行时出现如下错误:
未能启用约束。一行或多行中包含违反非空、唯一或外键约束的值。
单步调试时发现是在执行my_da.Fill(my_ds,"p_person");时出错。
还有一个问题就是怎么同时在显示出gw_liucheng_qm和p_person这两个表的内容。
6 个解决方案
#1
如果换成
ls_sql="select gw_liucheng_person.pid "+
" from GONGWEN_LIUCHENG_PERSON,GongWen_liucheng"+
" where GongWen_liucheng.GWID=GONGWEN_LIUCHENG_PERSON.GWID "+
"and GongWen_liucheng.bzid=GONGWEN_LIUCHENG_PERSON.bzid "+
"and GongWen_liucheng.GWID=1 ";
......
my_da.Fill(my_ds,"gw_liucheng_person");
就没错。奇怪啊?
表名打错了,gongwen=gw,呵呵
ls_sql="select gw_liucheng_person.pid "+
" from GONGWEN_LIUCHENG_PERSON,GongWen_liucheng"+
" where GongWen_liucheng.GWID=GONGWEN_LIUCHENG_PERSON.GWID "+
"and GongWen_liucheng.bzid=GONGWEN_LIUCHENG_PERSON.bzid "+
"and GongWen_liucheng.GWID=1 ";
......
my_da.Fill(my_ds,"gw_liucheng_person");
就没错。奇怪啊?
表名打错了,gongwen=gw,呵呵
#2
up
#3
up
#4
兄弟,你有没有解决啊,我遇到到样的问题?如果你有好的办法,请指点一下,谢谢
#5
给你个例子
//首先建立一个新项dataset,里面建立一个没有数据的元素,包含报表中需要的数据,并加一个id设为主健,通过dataset生成.rpt文件;下边设生成数据和邦顶的过程。
DataSet1 ds=new DataSet1();
xscjtj orc = new xscjtj();
int i=0 ,j;
string str_kc="";
conf.open();
strsql="SELECT t_xscjb.xq, V_kcbm.bmnr, t_xsjbxx.xsbh, t_xsjbxx.xm, t_xscjb.kccj, t_xsjbxx.sxsdm, t_xsjbxx.xxdm FROM jxgl.dbo.t_xsjbxx t_xsjbxx INNER JOIN jxgl.dbo.t_xscjb t_xscjb ON t_xsjbxx.xsbh=t_xscjb.xsbh INNER JOIN jxgl.dbo.V_kcbm V_kcbm ON t_xscjb.kcbh=V_kcbm.bm WHERE (t_xsjbxx.sxsdm='41' AND t_xsjbxx.xxdm='4109'";
cmd.CommandText=strsql;
cmd.Connection=conf.Myconn;
dr=cmd.ExecuteReader();
while(dr.Read())
{
DataRow r=ds.Tables[0].NewRow();
r["id"]=i++;
r["xq"]=dr["xq"].ToString().Trim();
r["bmnr"]=dr["bmnr"].ToString().Trim();
r["xsbh"]=dr["xsbh"].ToString().Trim();
r["xm"]=dr["xm"].ToString().Trim();
r["kccj"]=dr["kccj"].ToString().Trim();
ds.Tables[0].Rows.Add(r);
}
conf.close();
orc.SetDataSource(ds);
this.CRV_xscjgl.ReportSource = orc;
//首先建立一个新项dataset,里面建立一个没有数据的元素,包含报表中需要的数据,并加一个id设为主健,通过dataset生成.rpt文件;下边设生成数据和邦顶的过程。
DataSet1 ds=new DataSet1();
xscjtj orc = new xscjtj();
int i=0 ,j;
string str_kc="";
conf.open();
strsql="SELECT t_xscjb.xq, V_kcbm.bmnr, t_xsjbxx.xsbh, t_xsjbxx.xm, t_xscjb.kccj, t_xsjbxx.sxsdm, t_xsjbxx.xxdm FROM jxgl.dbo.t_xsjbxx t_xsjbxx INNER JOIN jxgl.dbo.t_xscjb t_xscjb ON t_xsjbxx.xsbh=t_xscjb.xsbh INNER JOIN jxgl.dbo.V_kcbm V_kcbm ON t_xscjb.kcbh=V_kcbm.bm WHERE (t_xsjbxx.sxsdm='41' AND t_xsjbxx.xxdm='4109'";
cmd.CommandText=strsql;
cmd.Connection=conf.Myconn;
dr=cmd.ExecuteReader();
while(dr.Read())
{
DataRow r=ds.Tables[0].NewRow();
r["id"]=i++;
r["xq"]=dr["xq"].ToString().Trim();
r["bmnr"]=dr["bmnr"].ToString().Trim();
r["xsbh"]=dr["xsbh"].ToString().Trim();
r["xm"]=dr["xm"].ToString().Trim();
r["kccj"]=dr["kccj"].ToString().Trim();
ds.Tables[0].Rows.Add(r);
}
conf.close();
orc.SetDataSource(ds);
this.CRV_xscjgl.ReportSource = orc;
#6
海波.NET
问题:
异常详细信息: System.Data.ConstraintException: 未能启用约束。一行或多行中包含违反非空、唯一或外键约束的值。
------------------------------------------------
解决方案:
DataSet.EnforceConstraints = false;
DataSet.EnforceConstraints 属性
DataSet 类 | DataSet 成员 | System.Data 命名空间 | Constraints | ConstraintException | ForeignKeyConstraint | DataTable | UniqueConstraint
获取或设置一个值,该值指示在尝试执行任何更新操作时是否遵循约束规则。
[Visual Basic]
<Serializable>
Public Property EnforceConstraints As Boolean
[C#]
[Serializable]
public bool EnforceConstraints {get; set;}
属性值
如果实施规则,则为 true;否则为 false。默认为 true。
异常
异常类型 条件
ConstraintException 无法实施一个或多个约束。
备注
有关详细信息,请参阅 Constraints 属性。
示例
[Visual Basic, C#] 以下示例创建一个 DataSet,该数据集包含一个表、一个列、五个行和一个 UniqueConstraint。EnforceConstraints 属性被设置为 false,每一行的值都设置为同一个值。如果 EnforceConstraints 属性被重置为 true,则生成 ConstraintException。
[Visual Basic]
Private Sub DemonstrateEnforceConstraints()
' Create a DataSet with one table, one column and a UniqueConstraint.
Dim ds As DataSet = New DataSet("myDataSet")
Dim t As DataTable = New DataTable("myTable")
Dim c As DataColumn = New DataColumn("col1")
c.Unique = True
t.Columns.Add(c)
ds.Tables.Add(t)
Console.WriteLine("constraints.count: " & t.Constraints.Count)
' add five rows.
Dim r As DataRow
Dim i As Integer
For i = 0 To 4
r = t.NewRow()
r("col1") = i
t.Rows.Add(r)
Next
t.AcceptChanges()
ds.EnforceConstraints = False
' Change the values of all rows to 1.
Dim thisRow As DataRow
For Each thisRow In t.rows
thisRow("col1") = 1
Next
Try
ds.EnforceConstraints = True
Catch ex As System.Data.ConstraintException
Console.WriteLine("ConstraintException: " + ex.Message)
End Try
End Sub
[C#]
private void DemonstrateEnforceConstraints(){
// Create a DataSet with one table, one column and a UniqueConstraint.
DataSet ds= new DataSet("myDataSet");
DataTable t = new DataTable("myTable");
DataColumn c = new DataColumn("col1");
// A UniqueConstraint is added when the Unique property is true.
c.Unique=true;
t.Columns.Add(c);
ds.Tables.Add(t);
Console.WriteLine("constraints.count: " + t.Constraints.Count);
// add five rows.
DataRow r ;
for(int i=0;i<5;i++){
r = t.NewRow();
r["col1"] = i;
t.Rows.Add(r);
}
t.AcceptChanges();
ds.EnforceConstraints=false;
// Change the values of all rows to 1.
foreach(DataRow thisRow in t.Rows){
thisRow["col1"]=1;
//Console.WriteLine("\t" + thisRow[0]);
}
try{
ds.EnforceConstraints=true;
}
catch(System.Data.ConstraintException ex){
Console.WriteLine("ConstraintException: " + ex.Message);
}
catch(System.Exception sysEx){
Console.WriteLine(sysEx.GetType().Name);
Console.WriteLine(sysEx.Message);
}
}
问题:
异常详细信息: System.Data.ConstraintException: 未能启用约束。一行或多行中包含违反非空、唯一或外键约束的值。
------------------------------------------------
解决方案:
DataSet.EnforceConstraints = false;
DataSet.EnforceConstraints 属性
DataSet 类 | DataSet 成员 | System.Data 命名空间 | Constraints | ConstraintException | ForeignKeyConstraint | DataTable | UniqueConstraint
获取或设置一个值,该值指示在尝试执行任何更新操作时是否遵循约束规则。
[Visual Basic]
<Serializable>
Public Property EnforceConstraints As Boolean
[C#]
[Serializable]
public bool EnforceConstraints {get; set;}
属性值
如果实施规则,则为 true;否则为 false。默认为 true。
异常
异常类型 条件
ConstraintException 无法实施一个或多个约束。
备注
有关详细信息,请参阅 Constraints 属性。
示例
[Visual Basic, C#] 以下示例创建一个 DataSet,该数据集包含一个表、一个列、五个行和一个 UniqueConstraint。EnforceConstraints 属性被设置为 false,每一行的值都设置为同一个值。如果 EnforceConstraints 属性被重置为 true,则生成 ConstraintException。
[Visual Basic]
Private Sub DemonstrateEnforceConstraints()
' Create a DataSet with one table, one column and a UniqueConstraint.
Dim ds As DataSet = New DataSet("myDataSet")
Dim t As DataTable = New DataTable("myTable")
Dim c As DataColumn = New DataColumn("col1")
c.Unique = True
t.Columns.Add(c)
ds.Tables.Add(t)
Console.WriteLine("constraints.count: " & t.Constraints.Count)
' add five rows.
Dim r As DataRow
Dim i As Integer
For i = 0 To 4
r = t.NewRow()
r("col1") = i
t.Rows.Add(r)
Next
t.AcceptChanges()
ds.EnforceConstraints = False
' Change the values of all rows to 1.
Dim thisRow As DataRow
For Each thisRow In t.rows
thisRow("col1") = 1
Next
Try
ds.EnforceConstraints = True
Catch ex As System.Data.ConstraintException
Console.WriteLine("ConstraintException: " + ex.Message)
End Try
End Sub
[C#]
private void DemonstrateEnforceConstraints(){
// Create a DataSet with one table, one column and a UniqueConstraint.
DataSet ds= new DataSet("myDataSet");
DataTable t = new DataTable("myTable");
DataColumn c = new DataColumn("col1");
// A UniqueConstraint is added when the Unique property is true.
c.Unique=true;
t.Columns.Add(c);
ds.Tables.Add(t);
Console.WriteLine("constraints.count: " + t.Constraints.Count);
// add five rows.
DataRow r ;
for(int i=0;i<5;i++){
r = t.NewRow();
r["col1"] = i;
t.Rows.Add(r);
}
t.AcceptChanges();
ds.EnforceConstraints=false;
// Change the values of all rows to 1.
foreach(DataRow thisRow in t.Rows){
thisRow["col1"]=1;
//Console.WriteLine("\t" + thisRow[0]);
}
try{
ds.EnforceConstraints=true;
}
catch(System.Data.ConstraintException ex){
Console.WriteLine("ConstraintException: " + ex.Message);
}
catch(System.Exception sysEx){
Console.WriteLine(sysEx.GetType().Name);
Console.WriteLine(sysEx.Message);
}
}
#1
如果换成
ls_sql="select gw_liucheng_person.pid "+
" from GONGWEN_LIUCHENG_PERSON,GongWen_liucheng"+
" where GongWen_liucheng.GWID=GONGWEN_LIUCHENG_PERSON.GWID "+
"and GongWen_liucheng.bzid=GONGWEN_LIUCHENG_PERSON.bzid "+
"and GongWen_liucheng.GWID=1 ";
......
my_da.Fill(my_ds,"gw_liucheng_person");
就没错。奇怪啊?
表名打错了,gongwen=gw,呵呵
ls_sql="select gw_liucheng_person.pid "+
" from GONGWEN_LIUCHENG_PERSON,GongWen_liucheng"+
" where GongWen_liucheng.GWID=GONGWEN_LIUCHENG_PERSON.GWID "+
"and GongWen_liucheng.bzid=GONGWEN_LIUCHENG_PERSON.bzid "+
"and GongWen_liucheng.GWID=1 ";
......
my_da.Fill(my_ds,"gw_liucheng_person");
就没错。奇怪啊?
表名打错了,gongwen=gw,呵呵
#2
up
#3
up
#4
兄弟,你有没有解决啊,我遇到到样的问题?如果你有好的办法,请指点一下,谢谢
#5
给你个例子
//首先建立一个新项dataset,里面建立一个没有数据的元素,包含报表中需要的数据,并加一个id设为主健,通过dataset生成.rpt文件;下边设生成数据和邦顶的过程。
DataSet1 ds=new DataSet1();
xscjtj orc = new xscjtj();
int i=0 ,j;
string str_kc="";
conf.open();
strsql="SELECT t_xscjb.xq, V_kcbm.bmnr, t_xsjbxx.xsbh, t_xsjbxx.xm, t_xscjb.kccj, t_xsjbxx.sxsdm, t_xsjbxx.xxdm FROM jxgl.dbo.t_xsjbxx t_xsjbxx INNER JOIN jxgl.dbo.t_xscjb t_xscjb ON t_xsjbxx.xsbh=t_xscjb.xsbh INNER JOIN jxgl.dbo.V_kcbm V_kcbm ON t_xscjb.kcbh=V_kcbm.bm WHERE (t_xsjbxx.sxsdm='41' AND t_xsjbxx.xxdm='4109'";
cmd.CommandText=strsql;
cmd.Connection=conf.Myconn;
dr=cmd.ExecuteReader();
while(dr.Read())
{
DataRow r=ds.Tables[0].NewRow();
r["id"]=i++;
r["xq"]=dr["xq"].ToString().Trim();
r["bmnr"]=dr["bmnr"].ToString().Trim();
r["xsbh"]=dr["xsbh"].ToString().Trim();
r["xm"]=dr["xm"].ToString().Trim();
r["kccj"]=dr["kccj"].ToString().Trim();
ds.Tables[0].Rows.Add(r);
}
conf.close();
orc.SetDataSource(ds);
this.CRV_xscjgl.ReportSource = orc;
//首先建立一个新项dataset,里面建立一个没有数据的元素,包含报表中需要的数据,并加一个id设为主健,通过dataset生成.rpt文件;下边设生成数据和邦顶的过程。
DataSet1 ds=new DataSet1();
xscjtj orc = new xscjtj();
int i=0 ,j;
string str_kc="";
conf.open();
strsql="SELECT t_xscjb.xq, V_kcbm.bmnr, t_xsjbxx.xsbh, t_xsjbxx.xm, t_xscjb.kccj, t_xsjbxx.sxsdm, t_xsjbxx.xxdm FROM jxgl.dbo.t_xsjbxx t_xsjbxx INNER JOIN jxgl.dbo.t_xscjb t_xscjb ON t_xsjbxx.xsbh=t_xscjb.xsbh INNER JOIN jxgl.dbo.V_kcbm V_kcbm ON t_xscjb.kcbh=V_kcbm.bm WHERE (t_xsjbxx.sxsdm='41' AND t_xsjbxx.xxdm='4109'";
cmd.CommandText=strsql;
cmd.Connection=conf.Myconn;
dr=cmd.ExecuteReader();
while(dr.Read())
{
DataRow r=ds.Tables[0].NewRow();
r["id"]=i++;
r["xq"]=dr["xq"].ToString().Trim();
r["bmnr"]=dr["bmnr"].ToString().Trim();
r["xsbh"]=dr["xsbh"].ToString().Trim();
r["xm"]=dr["xm"].ToString().Trim();
r["kccj"]=dr["kccj"].ToString().Trim();
ds.Tables[0].Rows.Add(r);
}
conf.close();
orc.SetDataSource(ds);
this.CRV_xscjgl.ReportSource = orc;
#6
海波.NET
问题:
异常详细信息: System.Data.ConstraintException: 未能启用约束。一行或多行中包含违反非空、唯一或外键约束的值。
------------------------------------------------
解决方案:
DataSet.EnforceConstraints = false;
DataSet.EnforceConstraints 属性
DataSet 类 | DataSet 成员 | System.Data 命名空间 | Constraints | ConstraintException | ForeignKeyConstraint | DataTable | UniqueConstraint
获取或设置一个值,该值指示在尝试执行任何更新操作时是否遵循约束规则。
[Visual Basic]
<Serializable>
Public Property EnforceConstraints As Boolean
[C#]
[Serializable]
public bool EnforceConstraints {get; set;}
属性值
如果实施规则,则为 true;否则为 false。默认为 true。
异常
异常类型 条件
ConstraintException 无法实施一个或多个约束。
备注
有关详细信息,请参阅 Constraints 属性。
示例
[Visual Basic, C#] 以下示例创建一个 DataSet,该数据集包含一个表、一个列、五个行和一个 UniqueConstraint。EnforceConstraints 属性被设置为 false,每一行的值都设置为同一个值。如果 EnforceConstraints 属性被重置为 true,则生成 ConstraintException。
[Visual Basic]
Private Sub DemonstrateEnforceConstraints()
' Create a DataSet with one table, one column and a UniqueConstraint.
Dim ds As DataSet = New DataSet("myDataSet")
Dim t As DataTable = New DataTable("myTable")
Dim c As DataColumn = New DataColumn("col1")
c.Unique = True
t.Columns.Add(c)
ds.Tables.Add(t)
Console.WriteLine("constraints.count: " & t.Constraints.Count)
' add five rows.
Dim r As DataRow
Dim i As Integer
For i = 0 To 4
r = t.NewRow()
r("col1") = i
t.Rows.Add(r)
Next
t.AcceptChanges()
ds.EnforceConstraints = False
' Change the values of all rows to 1.
Dim thisRow As DataRow
For Each thisRow In t.rows
thisRow("col1") = 1
Next
Try
ds.EnforceConstraints = True
Catch ex As System.Data.ConstraintException
Console.WriteLine("ConstraintException: " + ex.Message)
End Try
End Sub
[C#]
private void DemonstrateEnforceConstraints(){
// Create a DataSet with one table, one column and a UniqueConstraint.
DataSet ds= new DataSet("myDataSet");
DataTable t = new DataTable("myTable");
DataColumn c = new DataColumn("col1");
// A UniqueConstraint is added when the Unique property is true.
c.Unique=true;
t.Columns.Add(c);
ds.Tables.Add(t);
Console.WriteLine("constraints.count: " + t.Constraints.Count);
// add five rows.
DataRow r ;
for(int i=0;i<5;i++){
r = t.NewRow();
r["col1"] = i;
t.Rows.Add(r);
}
t.AcceptChanges();
ds.EnforceConstraints=false;
// Change the values of all rows to 1.
foreach(DataRow thisRow in t.Rows){
thisRow["col1"]=1;
//Console.WriteLine("\t" + thisRow[0]);
}
try{
ds.EnforceConstraints=true;
}
catch(System.Data.ConstraintException ex){
Console.WriteLine("ConstraintException: " + ex.Message);
}
catch(System.Exception sysEx){
Console.WriteLine(sysEx.GetType().Name);
Console.WriteLine(sysEx.Message);
}
}
问题:
异常详细信息: System.Data.ConstraintException: 未能启用约束。一行或多行中包含违反非空、唯一或外键约束的值。
------------------------------------------------
解决方案:
DataSet.EnforceConstraints = false;
DataSet.EnforceConstraints 属性
DataSet 类 | DataSet 成员 | System.Data 命名空间 | Constraints | ConstraintException | ForeignKeyConstraint | DataTable | UniqueConstraint
获取或设置一个值,该值指示在尝试执行任何更新操作时是否遵循约束规则。
[Visual Basic]
<Serializable>
Public Property EnforceConstraints As Boolean
[C#]
[Serializable]
public bool EnforceConstraints {get; set;}
属性值
如果实施规则,则为 true;否则为 false。默认为 true。
异常
异常类型 条件
ConstraintException 无法实施一个或多个约束。
备注
有关详细信息,请参阅 Constraints 属性。
示例
[Visual Basic, C#] 以下示例创建一个 DataSet,该数据集包含一个表、一个列、五个行和一个 UniqueConstraint。EnforceConstraints 属性被设置为 false,每一行的值都设置为同一个值。如果 EnforceConstraints 属性被重置为 true,则生成 ConstraintException。
[Visual Basic]
Private Sub DemonstrateEnforceConstraints()
' Create a DataSet with one table, one column and a UniqueConstraint.
Dim ds As DataSet = New DataSet("myDataSet")
Dim t As DataTable = New DataTable("myTable")
Dim c As DataColumn = New DataColumn("col1")
c.Unique = True
t.Columns.Add(c)
ds.Tables.Add(t)
Console.WriteLine("constraints.count: " & t.Constraints.Count)
' add five rows.
Dim r As DataRow
Dim i As Integer
For i = 0 To 4
r = t.NewRow()
r("col1") = i
t.Rows.Add(r)
Next
t.AcceptChanges()
ds.EnforceConstraints = False
' Change the values of all rows to 1.
Dim thisRow As DataRow
For Each thisRow In t.rows
thisRow("col1") = 1
Next
Try
ds.EnforceConstraints = True
Catch ex As System.Data.ConstraintException
Console.WriteLine("ConstraintException: " + ex.Message)
End Try
End Sub
[C#]
private void DemonstrateEnforceConstraints(){
// Create a DataSet with one table, one column and a UniqueConstraint.
DataSet ds= new DataSet("myDataSet");
DataTable t = new DataTable("myTable");
DataColumn c = new DataColumn("col1");
// A UniqueConstraint is added when the Unique property is true.
c.Unique=true;
t.Columns.Add(c);
ds.Tables.Add(t);
Console.WriteLine("constraints.count: " + t.Constraints.Count);
// add five rows.
DataRow r ;
for(int i=0;i<5;i++){
r = t.NewRow();
r["col1"] = i;
t.Rows.Add(r);
}
t.AcceptChanges();
ds.EnforceConstraints=false;
// Change the values of all rows to 1.
foreach(DataRow thisRow in t.Rows){
thisRow["col1"]=1;
//Console.WriteLine("\t" + thisRow[0]);
}
try{
ds.EnforceConstraints=true;
}
catch(System.Data.ConstraintException ex){
Console.WriteLine("ConstraintException: " + ex.Message);
}
catch(System.Exception sysEx){
Console.WriteLine(sysEx.GetType().Name);
Console.WriteLine(sysEx.Message);
}
}