Click here to Skip to main content
15,914,795 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am getting following error
This constraint cannot be enabled as not all values have corresponding parent values.
the code is :



Try
DB.connectDB()
Dim ds As New DataSet
Dim dt1 As DataTable = DB.selectRecord("SELECT tbl_Profile_View.ContractorID, COUNT(tbl_Profile_View.ContractorID) AS Profiles_View, realtygu_dbo.vwUsers.compName LoginName, realtygu_dbo.vwUsers.CompanyAddress, realtygu_dbo.vwUsers.PhoneNo, realtygu_dbo.vwUsers.CompanyEmail FROM tbl_Profile_View INNER JOIN realtygu_dbo.vwUsers ON tbl_Profile_View.ContractorID = realtygu_dbo.vwUsers.compID GROUP BY tbl_Profile_View.ContractorID, realtygu_dbo.vwUsers.compName, realtygu_dbo.vwUsers.CompanyAddress, realtygu_dbo.vwUsers.PhoneNo, realtygu_dbo.vwUsers.CompanyEmail order by tbl_Profile_View.ContractorID asc")


Dim dTable1 As DataTable = dt1.Copy
dTable1.TableName = "Parent"
ds.Tables.Add(dTable1)
Dim dt2 As DataTable = DB.selectRecord("SELECT tbl_Profile_View.ContractorID, COUNT(tbl_Profile_View.ContractorID) AS Profiles_View, realtygu_dbo.vwUsers.compName as LoginName, realtygu_dbo.vwUsers.CompanyAddress, realtygu_dbo.vwUsers.PhoneNo, realtygu_dbo.vwUsers.CompanyEmail, tbl_Profile_View.ClientID FROM tbl_Profile_View INNER JOIN realtygu_dbo.vwUsers ON tbl_Profile_View.ClientID = realtygu_dbo.vwUsers.compID GROUP BY tbl_Profile_View.ContractorID, realtygu_dbo.vwUsers.compName, realtygu_dbo.vwUsers.CompanyAddress, realtygu_dbo.vwUsers.PhoneNo, realtygu_dbo.vwUsers.CompanyEmail, tbl_Profile_View.ClientID order by tbl_Profile_View.ClientID asc ")

Dim dTable2 As DataTable = dt2.Copy
dTable2.TableName = "Child"
ds.Tables.Add(dTable2)
ds.Relations.Add("PK", ds.Tables(0).Columns("ContractorID"), ds.Tables(1).Columns("ContractorID"))
'ds.Tables(0).DefaultView.Sort = "InvoiceDate Desc"
ViewState("ds") = ds
hgProvider.DataSource = ds
hgProvider.DataMember = ds.Tables(0).TableName
hgProvider.DataBind()
Catch ex As Exception
Response.Write(ex.Message)
End Try

how it is solve please help me
thanks you
Posted

1 solution

You have created two data tables here(table1, table2).

and in both table there is some values, which you are selecting from database..
In your table there is some data which is producing confliction.. Try to remove the conflict between both..

or else just change a line in your code and try

VB
ds.Relations.Add("FK", ds.Tables(0).Columns("ContractorID"), ds.Tables(1).Columns("ContractorID"))


all the best.. :)
 
Share this answer
 
v2
Comments
joti parkash 24-Feb-12 7:19am    
can you explain the confliction in datatable
thanks you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900