Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

I just want to find the issue in my DataSet because its giving an error "
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints" while i am trying to join 2 data tables in one crystal report.

What I have tried:

<pre>? Pettycash_Details.GetErrors
Posted
Updated 14-May-21 9:04am
Comments
RedDk 25-May-21 17:37pm    
See the forms here:
https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/error-messages/name-name-is-not-declared
The SQL is ok ... but, as stated below, without data there's insufficient motivation for me to tackle anything in the "Try" block. And there's that too. A Try block from what?

1 solution

Your title has one error and then your body of the message has a totally different error. The title one means you are trying to call a function called pettycash_details somewhere but that somewhere cannot access it or pettycash_details does not exist.

The second error means whatever data you have and are working with does not match the constraints you have set.

These are both issues that you'll have to figure out since we have no access to anything you are doing.
 
Share this answer
 
Comments
Member 14976615 15-May-21 13:00pm    
Hi,

Can you please give me a solution for my second error pls:This is my code to Generate the Report:

Try
Cursor = Cursors.WaitCursor
Timer1.Enabled = True
Dim rpt As New rptVoucher
Dim myConnection As SqlConnection
Dim MyCommand As New SqlCommand()
Dim myDA As New SqlDataAdapter()
Dim myDS As New SchoolmanagementDataSet
myConnection = New SqlConnection(cs)
MyCommand.Connection = myConnection
MyCommand.CommandText = "Select Pettycash.ID,Pettycash.Pettycashno,Pettycash.Date,Pettycash.Accountno,Pettycash.Accountname,Pettycash.Amount,Pettycash_Details.VD_ID,Pettycash_Details.Accountname,Pettycash_Details.AccountNo,Pettycash_Details.Billref, Pettycash_Details.Narration, Pettycash_Details.Amount FROM Pettycash INNER JOIN Pettycash_Details On Pettycash.ID = Pettycash_Details.VoucherID where Pettycashno='" & txtVoucherNo.Text & "'"
MyCommand.CommandType = CommandType.Text
myDA.SelectCommand = MyCommand
'myDS.EnforceConstraints = False
myDA.Fill(myDS, "Pettycash")
myDA.Fill(myDS, "Pettycash_Details")
rpt.SetDataSource(myDS)
frmReport.CrystalReportViewer1.ReportSource = rpt
frmReport.ShowDialog()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub



This is my DataTable-1:
CREATE TABLE [dbo].[Pettycash] (
[ID] INT NOT NULL,
[Pettycashno] NCHAR (30) NULL,
[Date] DATE NULL,
[Accountno] NCHAR (150) NULL,
[Accountname] NCHAR (150) NULL,
[Amount] DECIMAL (18, 2) NULL,
[rnumber] NCHAR (150) NULL,
CONSTRAINT [PK_Pettycash] PRIMARY KEY CLUSTERED ([ID] ASC)
);




This is my DataTable-2;
CREATE TABLE [dbo].[Pettycash_Details] (
[VD_ID] INT IDENTITY (1, 1) NOT NULL,
[VoucherID] INT NULL,
[Date] DATE NULL,
[Accountname] NCHAR (150) NULL,
[AccountNo] NCHAR (150) NULL,
[Billref] NVARCHAR (50) NULL,
[Narration] NVARCHAR (MAX) NULL,
[Amount] DECIMAL (18, 2) NULL,
[rnumber] NCHAR (150) NULL,
CONSTRAINT [PK_Pettycash_Details] PRIMARY KEY CLUSTERED ([VD_ID] ASC),
CONSTRAINT [FK_Pettycash_Details_Pettycash] FOREIGN KEY ([VoucherID]) REFERENCES [dbo].[Pettycash] ([ID]) ON DELETE CASCADE ON UPDATE CASCADE
);



This is my DataSet Download Link;
https://drive.google.com/file/d/1m8CTh0S594saqtD2UaQwqpq6HFy-nVHB/view?usp=sharing
SeanChupas 17-May-21 8:52am    
You probably have something in SchoolmanagementDataSet that is causing it.
Member 14976615 17-May-21 23:30pm    
Hi, Can you please help me out to figure the Error please. this is my dataset link"https://drive.google.com/file/d/1m8CTh0S594saqtD2UaQwqpq6HFy-nVHB/view?usp=sharing". I have no idea about this i am very new in this field.I have tried to find through command window (GetError) but no use.Please Help me
SeanChupas 18-May-21 7:46am    
Sorry no. I am not downloading files from a stranger on the internet.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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