Results 1 to 5 of 5

Thread: failed to enable constrains.One or more rows contain value violating non-null,unique,

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2020
    Posts
    13

    Question failed to enable constrains.One or more rows contain value violating non-null,unique,

    Hi Everyone:
    I am trying to print my voucher data but its giving above mentioned error.I am very new in this field and tried several time to solved but failed.If any one can help me i will be thankful. Here is my code:
    Code:
    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 DataSet3
                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
                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
    Name:  mJ38h.jpg
Views: 392
Size:  34.0 KB
    Name:  TwKzW.png
Views: 338
Size:  8.3 KB

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: failed to enable constrains.One or more rows contain value violating non-null,uni

    As I commented on Stack Overflow, why are you executing the same query twice to populate two different DataTables? Either you want all the data in one DataTable, in which case you execute the query once, or you want it in two DataTables, in which case you execute two different queries with no join.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: failed to enable constrains.One or more rows contain value violating non-null,uni

    Also, what's up with this:
    Code:
    Dim myDS As New DataSet3
    What is a DataSet3 is that a typed DataSet? If so, why are you creating all your own ADO.NET objects instead of using table adapters?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2020
    Posts
    13

    Re: failed to enable constrains.One or more rows contain value violating non-null,uni

    Quote Originally Posted by jmcilhinney View Post
    Also, what's up with this:
    Code:
    Dim myDS As New DataSet3
    What is a DataSet3 is that a typed DataSet? If so, why are you creating all your own ADO.NET objects instead of using table adapters?
    Hi Sir,

    Yes DataSet3 is my DataSet

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2020
    Posts
    13

    Re: failed to enable constrains.One or more rows contain value violating non-null,uni

    Quote Originally Posted by jmcilhinney View Post
    As I commented on Stack Overflow, why are you executing the same query twice to populate two different DataTables? Either you want all the data in one DataTable, in which case you execute the query once, or you want it in two DataTables, in which case you execute two different queries with no join.
    Hi Sir,

    Actually i want it to in Two DataTables but i don't know how to execute two different queries with no join.Please help me out sir.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width